2624: Big Campus floyd

2624: Big Campus


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K9918Standard

JLU is a big university consists of six campus. Since it is so big, there are school buses running in it. School bus only stops at bus station. There are n bus stations in JLU, p1...pn. The bus has m route. Each starts and ends at bus station and spends some time. Xiaoming is standing at ps and wants to go to pe. So there comes the question, how fast can Xiaoming go to pe. Xiaoming's walking speed is v. Xiaoming can choose to go by bus or walk. He can even choose to take both. You can assume the bus goes once he get on.

Input

n, m // n <= 100, m <= n * n next n lines (xi, yi) coordinate of the bus station, float number next m lines i, j, t from the ith to jth spend t time v xs, ys // start point xe, ye // end point

Output

a float number, the minimal time, 3digit after dot

Sample Input

2 2
0 0
100 100
1 2 1
2 1 1
1
0 0
99 100

4 3
1 1
50 50
51 51
100 100
1 2 1
2 3 100
3 4 1
5
0 0
99 99

Sample Output

2.000
2.849

 

Problem Source: provided by zzc

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
class campus
{
    public:
    double x,y;
};
double distance(double x1,double y1,double x2,double y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
    campus a[105];
    int n,m;
    while(scanf("%d%d",&n,&m)==2)
    {
        double dis[105][105];
        for(int i=0;i<105;i++) for(int j=0;j<105;j++) dis[i][j]=(1<<31)-1;
        for(int i=1;i<=n;i++)
        {
            scanf("%lf%lf",&a[i].x,&a[i].y);
        }
        for(int i=1;i<=m;i++)
        {
            int xx,yy;
            double t;
            scanf("%d%d%lf",&xx,&yy,&t);
            if(t<dis[xx][yy])  dis[xx][yy]=t;
        }
        double v;
        scanf("%lf",&v);
        scanf("%lf%lf%lf%lf",&a[n+1].x,&a[n+1].y,&a[n+2].x,&a[n+2].y);
        for(int i=1;i<=n+2;i++)
            for(int j=1;j<=n+2;j++)
                    dis[i][j]=min(dis[i][j],distance(a[i].x,a[i].y,a[j].x,a[j].y)/v);
        /*for(int i=1;i<=n+2;i++)
          {

           for(int j=1;j<=n+2;j++)
                cout<<dis[i][j]<<".....";
                cout<<endl;
           }*/
        for(int k=1;k<=n+2;k++)
        {
            for(int i=1;i<=n+2;i++)
            {
                for(int j=1;j<=n+2;j++)
                {
                    dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
                }
            }
        }
        printf("%.3lf/n",dis[n+1][n+2]);
    }
    return 0;
}
/*
4 3
1 1
50 50
51 51
100 100
1 2 1
2 3 100
3 4 1
5
0 0
99 99
*/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值