#include<iostream>
using namespace std;
#define inf 0x7f7f7f7f7f7f7f7fLL
typedef __int64 LL;
LL mat[105][105];
LL cor[105];
LL L1,L2,L3,L4,C1,C2,C3,C4;
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 inf;
}
int n;
void floyd()
{ int i,j,k;
for(k=1;k<=n;k++)
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(mat[k][j]!=inf&&mat[i][k]!=inf)
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 i,j;
int m;
int cas=1;
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(i=1;i<=n;i++)
{ scanf("%I64d",&cor[i]);
}
for(i=1;i<=n;i++)
{ for(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]!=inf)
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;
}
hdu_1690
最新推荐文章于 2020-03-29 17:29:26 发布