hdu 1245 Saving James Bond

Saving James Bond

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3601    Accepted Submission(s): 769


Problem Description
This time let us consider the situation in the movie "Live and Let Die" in which James Bond, the world's most famous spy, was captured by a group of drug dealers. He was sent to a small piece of land at the center of a lake filled with crocodiles. There he performed the most daring action to escape -- he jumped onto the head of the nearest crocodile! Before the animal realized what was happening, James jumped again onto the next big head... Finally he reached the bank before the last crocodile could bite him (actually the stunt man was caught by the big mouth and barely escaped with his extra thick boot).
Assume that the lake is a 100×100 square one. Assume that the center of the lake is at (0,0) and the northeast corner at (50,50). The central island is a disk centered at (0,0) with the diameter of 15. A number of crocodiles are in the lake at various positions. Given the coordinates of each crocodile and the distance that James could jump, you must tell him whether he could escape.If he could,tell him the shortest length he has to jump and the min-steps he has to jump for shortest length.
 

Input
The input consists of several test cases. Each case starts with a line containing n <= 100, the number of crocodiles, and d > 0, the distance that James could jump. Then one line follows for each crocodile, containing the (x, y) location of the crocodile. Note that x and y are both integers, and no two crocodiles are staying at the same position.
 

Output
For each test case, if James can escape, output in one line the shortest length he has to jump and the min-steps he has to jump for shortest length. If it is impossible for James to escape that way, simply ouput "can't be saved".
 

Sample Input
  
  
4 10 17 0 27 0 37 0 45 0 1 10 20 30
 

Sample Output
  
  
42.50 5 can't be saved
 

Author
weigang Lee
 

Recommend
Ignatius.L   |   We have carefully selected several similar problems for you:   1317  1546  1535  1385  1531 


题意:一个人从直径为15米的小岛上踩着鲨鱼跳离湖,湖为100*100的正方形。人最大的跳跃距离为d,给出n个鲨鱼的坐标,求人跳跃的最小距离及在这情况下的跳跃次数。

把岛看做点1,湖外看做点n+1,先计算出这n+2个点之间的距离,若超过D则设为不连通,然后再用Floyd求最短路。(主要卡精度)

#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <queue>
#include <cmath>
#include <map>

using namespace std;
#define INF 0x3f3f3f3f
#define EPS 10e-6
#define N 200
int steps[N][N];
double dis[N][N];

double X[N], Y[N];
int n;
double m;
double min(double a, double b)
{
    return a < b ? a : b;
}
double distance(int x1, int y1, int x2, int y2)
{
    return sqrt(1.0 * ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
}
void floyd()
{
    for(int k = 1; k <= n+1; k++) {
        for(int i = 1; i <= n+1; i++) {
            for(int j = 1; j <= n+1; j++) {
                if(dis[i][j] > dis[i][k] + dis[k][j]) {
                    dis[i][j] = dis[i][k] + dis[k][j];
                    steps[i][j] = steps[i][k] + steps[k][j];
                }
            }
        }
    }
}
int main()
{

    while(scanf("%d%lf",&n, &m) != EOF) {
        int k = 2;
        for(int i = 1; i <= n; i++) {	//数据合法
            double x,y;
            scanf("%lf%lf",&x,&y);
            if(fabs(x)-7.5 <= EPS && abs(y)-7.5 <= EPS)
                continue;
            if(fabs(x)-50 >= EPS && fabs(y) - 50 >= EPS)
                continue;
            X[k] = x;
            Y[k++] = y;
        }
        n = k - 1;
        if(n == 1) {
            if(m - 42.5 < EPS)
                printf("42.50 1\n");
            else
                printf("can't be saved\n");
            continue;
        }
        X[1] = 0,Y[1] = 0;
        memset(steps, 0, sizeof(steps));
        for(int i = 1;i <= n+2; i++)
            for(int j = 1;j <= n + 2; j++) {
                if(i == j) {
                    dis[i][j] = 0;
                    continue;
                }
                dis[i][j] = INF;
            }


        for(int i = 1; i <= n; i++) {
            for(int j = i + 1; j <= n; j++) {
                double t = distance(X[i], Y[i], X[j], Y[j]);
                if(i == 1)
                    t -= 7.5;
                if(t - m > EPS)
                    continue;
                dis[i][j] = dis[j][i] = t;
                steps[i][j] = steps[j][i] = 1;
            }
        }
        for(int i = 1; i <= n; i++) {//岛外点距离
            double t = min(50 - X[i], 50 - Y[i]);
            t = min(t, min(50 + X[i], 50 + Y[i]));
            if(t - m > EPS)
                continue;
            dis[i][n+1] = dis[n+1][i] = t;
            steps[i][n+1] = steps[n+1][i] = 1;
        }
        floyd();
        //printf("%lf\n",dis[1][n+1] - INF);
        if(steps[1][n+1]==0)
            printf("can't be saved\n");
        else
            printf("%.2lf %d\n", dis[1][n+1],steps[1][n+1]);
    }

    return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值