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 ...
随机推荐
- kNN#约会网站预测数据
#约会网站预测数据 def classifyPersion(): resultList = ['not at all','in small doses','in large doses'] #inpu ...
- LOJ 6432 「PKUSC2018」真实排名——水题
题目:https://loj.ac/problem/6432 如果不选自己,设自己的值是 x ,需要让 “ a<x && 2*a>=x ” 的非 x 的值不被选:如果选自己 ...
- mybatis批量生成
使用了mybatis-generator后,寻找只写一个table标签就可以全部生成的方法 下载mybatis-generator-core-1.3.2-bundle.zip 解压后打开docs 发现 ...
- Archive.org:互联网档案馆
Archive.org:互联网档案馆 2009年的最后一天,辞旧迎新,互联网也同样如此,在过往40年的基础上一步步积累发展.对于我们而言很希望通过以往的每个网页.见证和找寻历史,这就是今天所介绍的 ...
- wsl中加载git之后,发现文件是修改状态
查看git status,发现所有文件都被修改. git diff文件查看,发现是行尾的问题导致的. https://github.com/Microsoft/WSL/issues/184 在wsl里 ...
- 在RedHat中安装新字体
安装 下载这个字体. http://pan.baidu.com/s/1c23znaS 密码:tldo 在/usr/share/fonts/truetype/, 下建立一个新的目录 YaHei Cons ...
- SQL语言分类DDL、DML、DQL、TCL、DCL
关系型数据库的SQL语句都可以分为4大类: 1. DDL(数据定义语言) DDL 主要是指如下的四种SQL 语句,以 CREATE.DROP.ALRET开头和 TRUNCATE TABLE 语 ...
- 建站手册-网站建设: Web 标准
ylbtech-建站手册-网站建设: Web 标准 1.返回顶部 1. http://www.w3school.com.cn/site/site_standards.asp 2. 2.返回顶部 1. ...
- Linux(Ubuntu)常用命令(四)
权限修改: 先知: u user 表示该文件的所有者 g group 表示与该文件的所有者属于同一组( group )者,即用户组 o other 表示其他以外的人 a all 表示这三者皆是 r r ...
- 方法Join()
等待线程结束:jion() 谦让: yeild() 睡眠: sleep() jion和sleep和yeild之间有什么区别呢? 首先介绍一下jion(): 如果想让主线程等待子线程执行完毕之后再继续运 ...