http://acm.hdu.edu.cn/showproblem.php?pid=1690
无穷大设置的不好,WA了3次,最后干脆改成-1过了。
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = 100+5;
const __int64 inf=-1;
__int64 map[maxn][maxn],dist[maxn][maxn];
__int64 L[5],C[5];
__int64 x[maxn];
__int64 abss(__int64 x)
{
if(x<0) x=x*(-1);
if(x<=L[1]) return C[1];
else if(x<=L[2]) return C[2];
else if(x<=L[3]) return C[3];
else if(x<=L[4]) return C[4];
return inf;
}
int n;
void floyd()
{
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++){
if(i==j) dist[i][j]=0;
else dist[i][j]=map[i][j];
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(dist[i][k]!=-1&&dist[k][j]!=-1&&(dist[i][j]>dist[i][k]+dist[k][j]||dist[i][j]==-1))
dist[i][j]=dist[i][k]+dist[k][j];
}
int main()
{
int T,m;
scanf("%d",&T);
for(int kas=1;kas<=T;kas++)
{
for(int i=1;i<5;i++) scanf("%I64d",&L[i]);
for(int i=1;i<5;i++) scanf("%I64d",&C[i]);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%I64d",&x[i]);
for(int j=1;j<i;j++)
map[i][j]=map[j][i]=abss(x[i]-x[j]);
}
floyd();
printf("Case %d:\n",kas);
while(m--)
{
int u,v;
scanf("%d%d",&u,&v);
if(dist[u][v]!=-1)
printf("The minimum cost between station %d and station %d is %I64d.\n",u,v,dist[u][v]);
else
printf("Station %d and station %d are not attainable.\n",u,v);
}
}
return 0;
}