标签:
public class MetroTransfor {
static int ver=37;
static int point=35;
static int [][] distance= new int[ver][ver];
static int [][] path= new int[ver][ver];
public static void main(String [] args){
initDistance();
initPath();
floyed();
}
private static void initPath() {
for(int row=0;row
for(int col=0;col
path[row][col]=row;
}
private static void floyed() {
for(int i=1 ; i<= ver; i++){
for(int j=1 ; j<= ver; j++){
for(int k= 1 ; k<= ver; k++){
if(distance[j][k]>distance[j][i]+distance[i][k]){
distance[j][k]=distance[j][i]+distance[i][k];
path[j][k] = path[i][k];
}
}
}
}
}
private static void initDistance() {
for(int i=1; i <=ver ;i++){
for(int j=1 ;j<=ver; j++){
if(i==j) distance[i][j]=0;
else distance[i][j] = 10000;//设置为不可达
}
}
int [] a = {0,1,2,3,4,5,6,7,8,33,9,10,11,12,13,35,14,15,16,17,0};//34 ,35 指T1,T2
int [] b = {18,19,20,21,22,33,23,24,25,26,27,34,28,35,29,30,31,32}; //34 ,35 指T1,T2
for(int i = 0;i
distance[a[i]][a[i+1]] = 1;
distance[a[i+1]][a[i]] = 1;
}
for(int i = 0;i
distance[b[i]][b[i+1]] = 1;
distance[b[i+1]][b[i]] = 1;
}
}
}
标签: