Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package problemdrogi;
- public class ProblemDrogi {
- /*
- package astro;
- public class Astro {
- public static void main(String[] args) {
- int[] astro = new int [4];
- int[][]as = {{1,1,0,0,1},{2,0,1,0,1},{3,0,1,1,0},{4,1,1,0,0},{5,0,0,1,1}};
- for(int i=0;i<=4;i++){
- for(int m=i+1;m<=4;m++){
- for(int l=1;l<=4;l++){
- astro[l-1]=as[i][l]+as[m][l];
- // System.out.print(astro[k][m-1]+" ");
- }
- if(((astro[0])*(astro[1])*(astro[2])*(astro[3]))>=1)
- System.out.println("Kosmonauci:"+(i+1)+" i "+(m+1));
- }
- }
- }
- }
- */
- public static void main(String[] args) {
- int[][]times = {{0,0,0,0,0,0,0,0,0},
- {0,0 ,300,402,356, 1 ,1 ,1 ,1 ,1 },
- {0,300,0 ,1 ,1 ,440,474,1 ,1 ,1 },
- {0,402,1 ,0 ,1 ,1 ,330,1 ,1 ,1 },
- {0,356,1 ,1 ,0 ,1 ,1 ,823,1 ,1 },
- {0,1 ,440,1 ,1 ,0 ,1 ,1 ,430,1 },
- {0,1 ,474,330,1 ,1 ,0 ,813,365,774},
- {0,1 ,1 ,1 ,823,1 ,813,0 ,1 ,403},
- {0,1 ,1 ,1 ,1 ,430,365,1 ,0 ,768},
- {0,1 ,1 ,1 ,1 ,1 ,774,403,768,0 }
- };
- int pomi=0,apomi=0,bpomi=0,cpomi=0,dpomi=0;
- int pomj=0,apomj=0,bpomj=0,cpomj=0,dpomj=0;
- int pomk=0,apomk=0,bpomk=0,cpomk=0,dpomk=0;
- int poml=0,apoml=0,bpoml=0,cpoml=0,dpoml=0;
- int pomm=0,apomm=0,bpomm=0,cpomm=0,dpomm=0;
- int pomn=0,apomn=0,bpomn=0,cpomn=0,dpomn=0;
- int pomo=0,apomo=0,bpomo=0,cpomo=0,dpomo=0;
- int pomp=0,apomp=0,bpomp=0;
- int min_time=100000;
- int t=0;
- System.out.println("Algorytm gdy znajdzie kombinacje z mniejszym czasem minimalnym automatycznie wypisuje ją na ekranie, ostatnia wypisana kompilacja będzie tą najbardziej optymalną.");
- for (int i = 2; i < 10; i++)
- for (int j = 2; j < 10; j++)
- for (int k = 3; k < 10; k++)
- for (int l = 4; l < 10; l++)
- for (int m = 5; m < 10; m++)
- for (int n = 6; n < 10; n++)
- for (int o = 7; o < 10; o++)
- for (int p = 8; p < 10; p++)
- {
- {
- {
- {
- {
- {
- {
- {
- {
- if(i==2)
- {
- apomi=times[1][i];
- bpomi=times[i][j];
- cpomi=times[i][1];
- dpomi=times[j][i];
- times[1][i]=0;
- times[i][j]=0;
- times[i][1]=0;
- times[j][i]=0;
- pomi=1;
- }
- if(j==2)
- {
- apomj=times[i][j];
- bpomj=times[j][i];
- cpomj=times[j][k];
- dpomj=times[k][j];
- times[i][j]=0;
- times[j][i]=0;
- times[j][k]=0;
- times[k][j]=0;
- pomj=1;
- }
- if(k==3)
- {
- apomk=times[k][l];
- bpomk=times[j][k];
- cpomk=times[l][k];
- dpomk=times[k][j];
- times[k][l]=0;
- times[j][k]=0;
- times[l][k]=0;
- times[k][j]=0;
- pomk=1;
- }
- if(l==4)
- {
- apoml=times[l][k];
- cpoml=times[l][m];
- dpoml=times[k][l];
- bpoml=times[m][l];
- times[l][k]=0;
- times[l][m]=0;
- times[k][l]=0;
- times[m][l]=0;
- poml=1;
- }
- if(m==5)
- {
- apomm=times[l][m];
- bpomm=times[n][m];
- cpomm=times[m][l];
- dpomm=times[m][n];
- times[l][m]=0;
- times[n][m]=0;
- times[m][l]=0;
- times[m][n]=0;
- pomm=1;
- }
- if(n==6)
- {
- apomn=times[m][n];
- bpomn=times[n][o];
- cpomn=times[n][m];
- dpomn=times[o][n];
- times[m][n]=0;
- times[n][o]=0;
- times[n][m]=0;
- times[o][n]=0;
- pomn=1;
- }
- if(o==7)
- {
- apomo=times[n][o];
- bpomo=times[o][p];
- cpomo=times[o][n];
- dpomo=times[p][o];
- times[n][o]=0;
- times[o][p]=0;
- times[o][n]=0;
- times[p][o]=0;
- pomo=1;
- }
- if(p==8)
- {
- apomp=times[o][p];
- bpomp= times[p][o];
- times[o][p]=0;
- times[p][o]=0;
- pomp=1;
- }
- t=times[1][i]+times[i][j]+times[j][k]+times[k][l]+times[l][m]+times[m][n]+times[n][o]+times[o][p]+times[p][9];
- if(min_time>t)
- {
- min_time=t;
- System.out.println("1 do "+i+"-> dlugosc:"+times[1][i]+", "+j+"-> dlugosc:"+times[i][j]+", "+k+"-> dlugosc:"+times[j][k]+", "+k+"-> dlugosc:"+times[k][l]+", "+l+"-> dlugosc:"+times[l][m]+", "+m+"-> dlugosc:"+times[m][n]+", "+n+"-> dlugosc:"+times[n][o]+", "+o+"-> dlugosc:"+times[o][p]+", "+p+"-> dlugosc:"+times[p][9]);
- // +j+"->"+k+"->"+l+"->"+ m+"->Sofia" + " Czas minimalny kombinacji: " + min_time);
- }
- }
- if(pomi==1)
- {
- times[1][i]=apomi;
- times[i][j]=bpomi;
- times[i][1]=cpomi;
- times[j][i]=dpomi;
- pomi=1;
- }
- if(pomj==1)
- {
- times[i][j]=apomj;
- times[j][i]=bpomj;
- times[j][k]=cpomj;
- times[k][j]=dpomj;
- pomj=0;
- }
- if(pomk==1)
- {
- times[k][l]=apomk;
- times[j][k]=bpomk;
- times[l][k]=cpomk;
- times[k][j]=dpomk;
- pomj=0;
- }
- if(poml==1)
- {
- times[l][k]=apoml;
- times[k][m]=bpoml;
- times[k][l]=cpoml;
- times[m][l]=dpoml;
- pomj=0;
- }
- if(pomm==1)
- {
- times[l][m]=apomm;
- times[n][m]=bpomm;
- times[m][l]=cpomm;
- times[m][n]=dpomm;
- pomj=0;
- }
- if(pomn==1)
- {
- times[m][n]=apomn;
- times[n][o]=bpomn;
- times[n][m]=cpomn;
- times[o][n]=dpomn;
- pomj=0;
- }
- if(pomo==1)
- {
- times[n][o]=apomo;
- times[o][p]=bpomo;
- times[o][n]=cpomo;
- times[p][o]=dpomo;
- pomj=0;
- }
- if(pomp==1)
- {
- times[o][p]=apomp;
- times[p][o]=bpomp;
- pomj=0;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- System.out.println("Kombinacja powyżej jest najbardziej optymalna");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement