HDU 1690 Bus System (Floyed求最短路)

题意: 坐公交 长度不同 票价不同

首先输入8个数L1 L2 L3 L4 C1 C2 C3 C4代表如果长度在 0-L1 花费 C1  L1-L2 花费C2  ....  超过L4 人家不拉你 - -

再输入n m 代表n个站 m个询问

接下来m行 每行两个数 代表所求的两点之间最短费用

最短路问题  由于点数只有100 所以直接Floyed即可

这题有个大坑... 不能再用1e9表示INF了  由于最大票价是1e9 所以我定义 INF = 2e9 很得意的认为自己发现了一个坑 然后就交了  无限WA - -! 但其实这是任意两站之间的 而实际有可能每两站之间都是INF 这样 总的票价可能达到 100×INF !!

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;

#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define REV(i, a, b) for(int i = b; i >= a; i--)

typedef long long LL;

const int maxn = 100 + 10;
const LL INF = 1LL<<40;

LL dist[maxn][maxn];
int n, m, cas = 0;
LL L[6], C[6], s[maxn];
pair<int, int> q[maxn*5];

void input(){
          L[0] = -1; C[0] = 0;
          L[1] = 0; C[5] = INF;
          FOR(i, 2, 5) scanf("%lld", &L[i]);
          FOR(i, 1, 4) scanf("%lld", &C[i]);
          scanf("%d%d", &n, &m);
          FOR(i, 1, n) scanf("%lld", &s[i]);
          FOR(i, 1, m) scanf("%d%d", &q[i].first, &q[i].second);
}

void solve(){
          FOR(i, 1, n) FOR(j, 1, n) dist[i][j] = INF;
          FOR(i, 1, n) FOR(j, 1, n){
                    int dis = abs(s[i] - s[j]);
                    REV(k, 0, 5) if(dis > L[k]){
                              dist[i][j] = C[k];
                              break;
                    }
          }
          FOR(k, 1, n) FOR(i, 1, n) FOR(j, 1, n)
                              dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
          printf("Case %d:\n", ++cas);
          FOR(i, 1, m){
                    LL d = dist[q[i].first][q[i].second];
                    if(d < INF)
                              printf("The minimum cost between station %d and station %d is %lld.\n", q[i].first, q[i].second, d);
                    else
                              printf("Station %d and station %d are not attainable.\n", q[i].first, q[i].second);
          }
}

int main()
{
//          freopen("in.txt", "r", stdin);
          int T;
          scanf("%d", &T);
          while(T--){
                    input();
                    solve();
          }
          return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值