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 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 分)的更多相关文章
- 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 ...
- 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 ...
- pat05-图2. Saving James Bond - Easy Version (25)
05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...
- 05-图2. Saving James Bond - Easy Version (25)
1 边界和湖心小岛分别算一个节点.连接全部距离小于D的鳄鱼.时间复杂度O(N2) 2 推断每一个连通图的节点中是否包括边界和湖心小岛,是则Yes否则No 3 冗长混乱的函数參数 #include &l ...
- Saving James Bond - Easy Version (MOOC)
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...
- 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 ...
- PAT Saving James Bond - Easy Version
Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- nofollow标签的作用 nofollow标签添加方法
这篇文章主要介绍了nofollow标签的作用 nofollow标签添加方法,需要的朋友可以参考下 nofollow标签的作用 nofollow标签添加方法 模拟搜狗蜘蛛 nofollow标签 ...
- Python基础教程(017)--执行Python的方式解释器运行及其他几种解释器简介
前言 了解Python的解释器 内容 Python的解释器乳交有多个语言的实现 cPython---官方版本的C语言实现 Jython--可以运行在java平台 IronPython--可以运行在.n ...
- angualr6 引入iframe
项目开发中需要在angular项目中嵌入iframe窗口,上网搜索了相关文档,不是很多,但是总算是把功能实现了,现记录一下,便于后期查看: step1:在.html中放入需要承载内容的div,并定义好 ...
- [HDU2604]Queuing
题目:Queuing 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2604 分析: 1)将当前格和上一格合并当作一个状态,考虑下一个格子放0(m)还是1( ...
- UE编辑器
引用ue的js 下载地址http://pan.baidu.com/s/1gdrQ35L <script type="text/javascript" src="__ ...
- 120、TensorFlow创建计算图(二)
#创建一个计算流图 #大多数tensorflow程序开始于dataflow graph 的构造函数 #在这个命令中你执行了tensorflow api的函数 #创建了新的操作tf.Operation ...
- jmeter添加自定义扩展函数之String---base64加密
1,打开eclipse,新建maven工程,在pom中引用jmeter核心jar包,具体请看---https://www.cnblogs.com/guanyf/p/10863033.html---,这 ...
- 用 Flask 来写个轻博客 (23) — 应用 OAuth 来实现 Facebook 第三方登录
目录 目录 前文列表 扩展阅读 第三方登录流程 OAuth 应用 OAuth 实现 Facebook 第三方登录 实现效果 前文列表 用 Flask 来写个轻博客 (1) - 创建项目 用 Flask ...
- pdf兼容问题不能正常预览
刚开始以为是这个PDF文件过大导致的 发现其他更大的文件也能正常显示 考虑到PDF的兼容问题 由于导出的PDF格式不兼容导致,如果有这种情况,可以尝试用word2016打开pdf文件,再导出成pdf.
- 基于全局地址池的DHCP
一.实验目的 二.实验拓扑图 .三.实验编址 四.实验步骤 1.配置IP 2.配置基于全局地址池的DHCP server 使用IP pool命令创建一个新的全局地址池,名称为hjt1 配置hjt1可动 ...