資源簡介
迪杰斯特拉動態規劃最短路徑,用C++實現的代碼。可以解決疏散問題
代碼片段和文件信息
#include
#include
??using?namespace?std;
???float?v(float?n)
????{
???? return?(1-0.266*0.5*(1+n/3));
????
}
???const?float?inf=100000;
???const?int?n=41;
???float?dis[n][n];
?vector?path[n][n];
?int?main()
??{
??
?
?? ?#ifndef?ONLINE_JUDGE
freopen(“input.txt“?“rt“?stdin);
freopen(“output.txt“?“wt+“?stdout);
#endif
??? ?float?L[41][41];
??? ?float?n[41];
??? ??for?(int?i=0;i<=40;i++)
??? ???for?(int?j=0;j<=40;j++)
??? ????L[i][j]=inf;
??? ????L[0][1]=5;
??? ????L[1][2]=0.7;
??? ????L[1][3]=1;
??? ????L[2][4]=1;
??? ????L[3][4]=0.7;
??? ????L[3][38]=0.75;
??? ????L[4][39]=0.75;
??? ????L[5][38]=0.7;
??? ????L[5][6]=0.6;
??? ????L[5][8]=0.6;
??? ????L[7][8]=1;
??? ????L[8][9]=1;
??? ????L[7][10]=1;
??? ????L[9][10]=1;
??? ????L[10][11]=0.5;
??? ????L[11][12]=2;
??? ????L[11][13]=0.5;
??? ????L[12][14]=0.5;
??? ????L[14][15]=1.3;
??? ????L[15][16]=1.2;
??? ????L[16][17]=0.6;
??? ????L[17][18]=1;
??? ????L[18][19]=1;
??? ????L[19][20]=1;
??? ????L[20][21]=1.2;
??? ????L[21][22]=1.3;
??? ????L[22][23]=0.5;
??? ????L[23][24]=2;
??? ????L[24][25]=1;
??? ????L[25][26]=1;
??? ????L[26][37]=2;
??? ????L[26][27]=1.5;
??? ????L[27][28]=0.5;
??? ????L[35][37]=2;
??? ????L[28][36]=1;
??? ????L[35][36]=1;
??? ????L[28][29]=0.6;
??? ????L[29][30]=1.4;
??? ????L[30][34]=1;
??? ????L[30][31]=1.2;
??? ????L[31][32]=1;
??? ????L[32][33]=1;
??? ????L[33][40]=4.5;
??? ????for?(int?i=0;i<=40;i++)
???for?(int?j=0;j<=i;j++)
????L[i][j]=L[j][i];
for?(int?i=0
評論
共有 條評論