HDU 1690

这道题目的意思我倒是看懂了,数据也过的了,但是就是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;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值