这道题目的意思我倒是看懂了,数据也过的了,但是就是WA了,后来重敲了一遍,把floyd函数放里面就过了!
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
const int maxn=105;
__int64 mp[maxn][maxn];
__int64 b[maxn];
int main()
{
int t;
int n,m;
int tcase;
int i,j,k,temp;
__int64 l1,l2,l3,l4,c1,c2,c3,c4;
scanf("%d",&t);
tcase=0;
while(t--)
{
scanf("%I64d%I64d%I64d%I64d%I64d%I64d%I64d%I64d",&l1,&l2,&l3,&l4,&c1,&c2,&c3,&c4);
scanf("%d%d",&n,&m);
for(i=1; i<=n; i++)
{
scanf("%I64d",&b[i]);
}
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
if(i==j)mp[i][j]=0;
else
{
temp=fabs(b[i]-b[j]);
if(temp<=l1)
mp[i][j]=c1;
else if(temp<=l2)
mp[i][j]=c2;
else if(temp<=l3)
mp[i][j]=c3;
else if(temp<=l4)
mp[i][j]=c4;
else if(temp>l4)
mp[i][j]=-1;
}
}
}
for(k=1; k<=n; k++)
{
for(i=1; i<=n; i++)
{
for(j=1; j<=n; j++)
{
if(mp[i][k]!=-1&&mp[k][j]!=-1)
{
if(mp[i][j]>mp[i][k]+mp[k][j]||mp[i][j]==-1)
{
mp[i][j]=mp[i][k]+mp[k][j];
}
}
}
}
}
printf("Case %d:\n",++tcase);
for(i=1; i<=m; i++)
{
int x,y;
scanf("%d%d",&x,&y);
if(mp[x][y]!=-1)
{
printf("The minimum cost between station %d and station %d is %I64d.\n",x,y,mp[x][y]);
}
else
{
printf("Station %d and station %d are not attainable.\n",x,y);
}
}
}
return 0;
}