这一题太蛋疼了,,,,建图太麻烦了,,,,
#include<iostream> #include<cstdio> using namespace std; #define M 0x7f7f7f7f7f7f7f7fLL typedef long long LL; LL mat[105][105]; LL cor[105]; LL L1,L2,L3,L4,C1,C2,C3,C4; int n,m; LL change(LL x) { if(x<0) x*=-1; if(x>0&&x<=L1) return C1; if(x>L1&&x<=L2) return C2; if(x>L2&&x<=L3) return C3; if(x>L3&&x<=L4) return C4; if(x>L4) return M; } void floyd() { for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(mat[k][j]!=M&&mat[i][k]!=M) if(mat[i][j]>mat[i][k]+mat[k][j]) mat[i][j]=mat[i][k]+mat[k][j]; } int main() { int t; scanf("%d",&t); int cas=0; while(t--) { printf("Case %d:\n",++cas); scanf("%I64d %I64d %I64d %I64d %I64d %I64d %I64d %I64d",&L1,&L2,&L3,&L4,&C1,&C2,&C3,&C4); scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%I64d",&cor[i]); for(int i=1;i<n;i++) { for(int j=i+1;j<=n;j++) { LL x=cor[i]-cor[j]; mat[i][j]=mat[j][i]=change(x); } } floyd(); while(m--) { int x,y; cin>>x>>y; if(mat[x][y]!=M) printf("The minimum cost between station %d and station %d is %I64d.\n",x,y,mat[x][y]); else cout<<"Station "<<x<<" and station "<<y<<" are not attainable."<<endl; } } return 0; }