Thunder Mountain - UVa 10803 Floyd

76 篇文章 0 订阅

Problem ?
Thunder Mountain
Time Limit: 3 seconds

"I mean, some people got guns, and some
people got flashlights, and some people got 
batteries. These guys had all three."

J. Michael Straczynski, "Jeremiah."

Markus is building an army to fight the evil Valhalla Sector, so he needs to move some supplies between several of the nearby towns. The woods are full of robbers and other unfriendly folk, so it's dangerous to travel far. As Thunder Mountain's head of security, Lee thinks that it is unsafe to carry supplies for more than 10km without visiting a town. Markus wants to know how far one would need to travel to get from one town to another in the worst case.

Input
The first line of input gives the number of cases, NN test cases follow. Each one starts with a line containing n (the number of towns, 1<n<101). The next n lines will give the xy-locations of each town in km (integers in the range [0, 1023]). Assume that the Earth is flat and the whole 1024x1024 grid is covered by a forest with roads connecting each pair of towns that are no further than 10km away from each other.

Output
For each test case, output the line "Case #x:", where x is the number of the test case. On the next line, print the maximum distance one has to travel from town A to town B (for some A and B). Round the answer to 4 decimal places. Every answer will obey the formula

fabs(ans*1e4 - floor(ans*1e4) - 0.5) > 1e-2

If it is impossible to get from some town to some other town, print "Send Kurdy" instead. Put an empty line after each test case.

Sample InputSample Output
2
5
0 0
10 0
10 10
13 10
13 14
2
0 0
10 1
Case #1:
25.0000

Case #2:
Send Kurdy


题意:给你n个点的坐标,问是否每两个点之间都可以通过点与点不超过10的路径连接起来。如果可以的话,输出最大的需要路线距离。

思路:简单的Floyd,没什么好说的。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
double INF=1e9,dis[110][110],x[110],y[110],eps=1e-8;
int T,t,n;
void Floyd()
{
    int i,j,k;
    for(k=1;k<=n;k++)
       for(i=1;i<=n;i++)
          for(j=1;j<=n;j++)
             dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
}
int main()
{
    int i,j,k;
    double ret;
    scanf("%d",&T);
    for(t=1;t<=T;t++)
    {
        scanf("%d",&n);
        for(i=1;i<=n;i++)
           scanf("%lf%lf",&x[i],&y[i]);
        for(i=1;i<=n;i++)
           for(j=i;j<=n;j++)
           {
               ret=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
               if(ret<10+eps)
                dis[i][j]=dis[j][i]=ret;
               else
                 dis[i][j]=dis[j][i]=INF;
           }
        Floyd();
        printf("Case #%d:\n",t);
        ret=0;
        for(i=1;i<=n;i++)
           for(j=1;j<=n;j++)
              ret=max(ret,dis[i][j]);
        if(ret<INF-eps)
          printf("%.4f\n\n",ret);
        else
          printf("Send Kurdy\n\n");
    }
}



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值