Bus System

这一题太蛋疼了,,,,建图太麻烦了,,,,

#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; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值