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 by 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 or not he can escape.

Input Specification:

Each input file contains one test case. Each case starts with a line containing two positive integers N (≤), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the ( location of a crocodile. Note that no two crocodiles are staying at the same position.

Output Specification:

For each test case, print in a line "Yes" if James can escape, or "No" if not.

Sample Input 1:

14 20
25 -15
-25 28
8 49
29 15
-35 -2
5 28
27 -29
-8 -28
-20 -35
-25 -20
-13 29
-30 15
-35 40
12 12

Sample Output 1:

Yes

Sample Input 2:

4 13
-12 12
12 12
-12 -12
12 -12

Sample Output 2:

No

我的答案,岛居然有15的直径T.T
 #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h> struct Crocodile {
int x;
int y;
int Visited;
};
typedef struct Crocodile *Point; int ReadPoint(Point P, int N);
void PrintPoint(Point P, int N);
double PointDistance(Point P1, Point P2);
int DFS(Point P, int N, double D, int stand);
int IsUp(Point P, int stand, double D); int ReadPoint(Point P, int N)
{
int i;
P[].x = ;
P[].y = ;
P[].Visited = ;
for(i=;i<N;i++) {
scanf("%d %d\n", &P[i].x, &P[i].y);
P[i].Visited = ;
}
return ;
} void PrintPoint(Point P, int N)
{
int i;
for(i=;i<N;i++) {
printf("P[%d] X:%d Y:%d\n", i, P[i].x, P[i].y);
}
printf("----------------------------\n");
} double PointDistance(Point P1, Point P2)
{
return sqrt(pow((P1->x - P2->x), ) + pow((P1->y - P2->y), ));
} int IsUp(Point P, int stand, double D)
{
int xlen = -abs(P[stand].x);
int ylen = -abs(P[stand].y);
if(stand == && (xlen<=(D+7.5)
|| ylen<=(D+7.5))) {
return ;
} else if(stand!= && (xlen<=D || ylen<=D)) {
return ;
}
return ; //Not
} int DFS(Point P, int N, double D, int stand)
{
int i, ret=, isup, island;
// printf("p[%d] X:%d Y:%d ", stand, P[stand].x, P[stand].y);
P[stand].Visited = ;
if(stand == ) island = ;
isup = IsUp(P, stand, D);
if(isup) {
// printf("stand %d\n", stand);
return ;
}
for(i=;i<N;i++) {
if(!P[i].Visited && (PointDistance(&P[i], &P[stand]) <= (D+island*7.5))) {
// printf("D:%lf\n", PointDistance(&P[i], &P[stand]));
ret = DFS(P, N, D, i);
if(ret) {
return ret;
}
}
}
return ret;
} int main()
{
int N;
double D;
Point P, S; S = (Point)malloc(sizeof(struct Crocodile));
S->x = ;
S->y = ; scanf("%d %lf\n", &N, &D);
N++; //N = N + 1;
P = (Point)malloc(sizeof(struct Crocodile)*N);
ReadPoint(P, N);
// PrintPoint(P, N);
if(DFS(P, N, D, ))
printf("Yes\n");
else
printf("No\n"); return ;
}

06-图2 Saving James Bond - Easy Version(25 分)的更多相关文章

  1. PTA 06-图2 Saving James Bond - Easy Version (25分)

    This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...

  2. 06-图2 Saving James Bond - Easy Version (25 分)

    This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...

  3. pat05-图2. Saving James Bond - Easy Version (25)

    05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...

  4. 05-图2. Saving James Bond - Easy Version (25)

    1 边界和湖心小岛分别算一个节点.连接全部距离小于D的鳄鱼.时间复杂度O(N2) 2 推断每一个连通图的节点中是否包括边界和湖心小岛,是则Yes否则No 3 冗长混乱的函数參数 #include &l ...

  5. Saving James Bond - Easy Version (MOOC)

    06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...

  6. Saving James Bond - Easy Version 原创 2017年11月23日 13:07:33

    06-图2 Saving James Bond - Easy Version(25 分) This time let us consider the situation in the movie &q ...

  7. PAT Saving James Bond - Easy Version

    Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...

  8. PTA 07-图5 Saving James Bond - Hard Version (30分)

    07-图5 Saving James Bond - Hard Version   (30分) This time let us consider the situation in the movie ...

  9. 06-图2 Saving James Bond - Easy Version

    题目来源:http://pta.patest.cn/pta/test/18/exam/4/question/625 This time let us consider the situation in ...

  10. 06-图2 Saving James Bond - Easy Version (25 分)

    This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...

随机推荐

  1. Security基础(三):OpenSSL及证书服务、邮件TLS/SSL加密通信

    一.OpenSSL及证书服务 目标: 本案例要求熟悉OpenSSL工具的基本使用,完成以下任务操作: 使用OpenSSL加密/解密文件 搭建企业自有的CA服务器,为颁发数字证书提供基础环境 方案: 使 ...

  2. BZOJ 1018: [SHOI2008]堵塞的交通traffic(线段树分治+并查集)

    传送门 解题思路 可以离线,然后确定每个边的出现时间,算这个排序即可.然后就可以线段树分治了,连通性用并查集维护,因为要撤销,所以要按秩合并,时间复杂度\(O(nlog^2 n)\) 代码 #incl ...

  3. html中map标签和area标签的应用(总结)

    html中map标签和area标签的应用(总结) 一.总结 一句话总结: html中map标签和area标签和组成图片地图,在前端优化中可以减少http请求 1.map标签的用途是什么? 图片地图:是 ...

  4. JAVA 大数开方模板

    JAVA 大数开方模板 import java.math.BigInteger; import java.math.*; import java.math.BigInteger; import jav ...

  5. [python面试题] 什么是单例,单例有什么用,业务场景是什么

    单例概念: 单例是一个特殊的类,这个类只能创建一次实例,例子如下: 1.a = Std(name='leo'), b = Std(name='jack'),两者的指向都是name=‘leo’的对象: ...

  6. TypeError: write() argument must be str, not bytes报错

    TypeError: write() argument must be str, not bytes 之前文件打开的语句是: with open('C:/result.pk','w') as fp: ...

  7. 第十三周学习总结&实验报告(八)

    图像界面 件处理及监听处理 1.键盘事件(KeyEvent)及监听处理(KeyListener) 1.1加入事件监听 super.addWindowListener(new WindowAdapter ...

  8. 搭建干净的Mac开发学习环境

    docker + linux + gcc/g++ https://www.jianshu.com/p/d113db99fe24 https://www.jianshu.com/p/d26140d20c ...

  9. HDU 3571 N-dimensional Sphere( 高斯消元+ 同余 )

    N-dimensional Sphere Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  10. document.location window.location

    document.location 和 window.location 取url的值的时候可以通用,但是 document是window的属性,所以不能直接用document.location =ur ...