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): 2764    Accepted Submission(s): 540


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 1535 1385 1531 1596 
 
最短路的变形,数据只有100,所以可以使用佛洛依德,不过记录每个点之前的距离有点麻烦,别忘了起始距离和最后一跳的结束距离。
 

题目大意:有一个100*100的正方形湖,湖中间有一个直径为15的圆形小岛;有n个点随机分布在这个正方形中;一个人要从小岛上跳出湖外,可以跳跃在这些点上;人每一步能跳的最大距离为d;求能跳出湖外所需的最小的跳跃距离和步数;

 

附上代码:

 

  1 #include <iostream>
  2 #include <cstdio>
  3 #include <cstring>
  4 #include <cmath>
  5 #define M 105
  6 #define MAX 0x3f3f3f3f
  7 using namespace std;
  8 double xx(double a)
  9 {
 10     return a>0?a:-a;
 11 }
 12 double min(double a,double b)
 13 {
 14     return a>b?b:a;
 15 }
 16 struct node
 17 {
 18     double x,y;
 19 } ss[M];
 20 double map[M][M];
 21 int s[M][M],n;
 22 
 23 void floyd()
 24 {
 25     int i,j,k;
 26     for(k=0; k<=n; k++)
 27         for(i=0; i<=n; i++)
 28             for(j=0; j<=n; j++)
 29                 if(map[i][j]>map[i][k]+map[k][j])
 30                 {
 31                     map[i][j]=map[i][k]+map[k][j];
 32                     s[i][j]=s[i][k]+s[k][j];
 33                 }
 34 }
 35 int main()
 36 {
 37     int m,i,j;
 38     int len1,len2;
 39     int a[M],b[M];
 40     double x,y,d;
 41     while(~scanf("%d%lf",&n,&d))
 42     {
 43         int len=1;
 44         for(i=1; i<=n; i++)
 45         {
 46             scanf("%lf%lf",&x,&y);
 47             if(xx(x)<=7.5 && xx(y)<=7.5) //只将所有在小岛外的点存入图中
 48                 continue;
 49             ss[len].x=x;
 50             ss[len++].y=y;
 51         }
 52         n=len;
 53         if(n==1) //没有落脚的点,直接判断
 54         {
 55             if(d>=42.5)   //判断能不能一步跳出湖
 56                 printf("42.50 1\n");
 57             else
 58                 printf("can't be saved\n");
 59             continue;
 60         }
 61         for(i=0; i<=n; i++)
 62             for(j=0; j<=n; j++)
 63             {
 64                 map[i][j]=MAX;
 65                 s[i][j]=0;
 66             }
 67         for(i=1; i<n; i++)
 68         {
 69             for(j=1; j<n; j++)
 70             {
 71                 if(i==j)
 72                 {
 73                     map[i][j]=0;
 74                     continue;
 75                 }
 76                 map[i][j]=sqrt((ss[i].x-ss[j].x)*(ss[i].x-ss[j].x)+(ss[i].y-ss[j].y)*(ss[i].y-ss[j].y));
 77                 //枚举所有距离
 78                 s[i][j]=1;
 79                 if(map[i][j]>d)//距离不够的时候,将该点变为无穷大
 80                 {
 81                     map[i][j]=MAX;
 82                     s[i][j]=0;
 83                 }
 84             }
 85         }
 86         len1=len2=0;
 87         for(i=1; i<n; i++)
 88         {
 89             if(sqrt(ss[i].x*ss[i].x+ss[i].y*ss[i].y)<=7.5+d)//起始点必须是从小岛上出发,距离能到达的点
 90                 a[len1++]=i;
 91             if((50+ss[i].x)<=d || (50-ss[i].x)<=d || (50+ss[i].y)<=d || (50-ss[i].y)<=d )//借这个点所有能到达岸边的点
 92                 b[len2++]=i;
 93         }
 94         for(i=0; i<len1; i++)
 95         {
 96             map[0][a[i]]=map[a[i]][0]=sqrt(ss[a[i]].x*ss[a[i]].x+ss[a[i]].y*ss[a[i]].y)-7.5;//小岛到起始点的距离
 97             s[0][a[i]]=s[a[i]][0]=1;
 98         }
 99         for(i=0; i<len2; i++)
100         {
101             map[b[i]][n]=map[n][b[i]]=min(min(50+ss[b[i]].x,50-ss[b[i]].x),min(50+ss[b[i]].y,50-ss[b[i]].y));//结束点到岸边的最短距离
102             s[b[i]][n]=s[n][b[i]]=1;
103         }
104         floyd();
105         if(map[0][n]<MAX)
106             printf("%.2lf %d\n",map[0][n],s[0][n]);
107         else
108             printf("can't be saved\n");
109     }
110     return 0;
111 }

 

posted @ 2016-04-13 16:42  lucky_少哖  阅读(171)  评论(0编辑  收藏  举报