码迷,mamicode.com
首页 > 其他好文 > 详细

HDU1690(Floyd)

时间:2015-03-11 21:42:07      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

一开始我以为直线上怎么会有最短距离,后来发现每两点之间直接到和间接到达的距离一样的,比如 1 ->2->3 = 1->2+2->3但是不等于1->3的直接距离

建完图以后直接Floyd就行,还有就是long long 会WA ,用__int64

#include <iostream>
#include <string.h>
#include <queue>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define maxn 1200
#define LL __int64
const LL  INF = 100000000002;
LL sit[maxn];
LL dis[maxn][maxn];
int  main()
{
#ifdef xxz
    freopen("in.txt","r",stdin);
#endif // xxz
    LL Case,L1,L2,L3,L4,C1,C2,C3,C4,n,m,v,T;
    cin>>T;
    Case = 1;
    while(T--)
    {
        cin>>L1>>L2>>L3>>L4>>C1>>C2>>C3>>C4;
        cin>>n>>m;
        for(LL i = 1; i <= n; i++)
        {
            cin>>sit[i];
            dis[i][i] = 0;
            for(LL j = 1; j < i; j++ )
            {
                LL temp = max(sit[i],sit[j]) - min(sit[i],sit[j]);
                if(temp > L4)  v = INF;
                else if(temp > L3) v = C4;
                else if(temp > L2) v= C3;
                else if(temp > L1) v = C2;
                else if(temp > 0) v = C1;
                else v = 0;
                dis[i][j] = dis[j][i] = v;
            }
        }

        for(LL k = 1; k <= n; k++)
            for(LL i = 1; i <= n; i++)
                for(LL j = 1; j<= n; j++)
                {
                    dis[i][j] = min(dis[i][j],dis[i][k] + dis[k][j]);
                }
        printf("Case %d:\n",Case++);
        for(LL i = 0; i < m; i++)
        {
            LL a,b;
            cin>>a>>b;
            if(dis[a][b]== INF ) printf("Station %I64d and station %I64d are not attainable.\n",a,b);
            else printf("The minimum cost between station %I64d and station %I64d is %I64d.\n",a,b,dis[a][b]);
        }
    }
    return 0;
}


HDU1690(Floyd)

标签:

原文地址:http://blog.csdn.net/u013445530/article/details/44204507

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!