pat05-图2. Saving James Bond - Easy Version (25)
05-图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 (<=100), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the (x, y) 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
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<string>
using namespace std;
struct point{
int x,y;
double dis;
bool vis;
point(){
vis=false;
}
};
double getdis(int x1,int y1,int x2,int y2){
int dx=x1-x2;
int dy=y1-y2;
return sqrt(dx*dx+dy*dy);
}
int abs(int a){
if(a<){
a=-a;
}
return a;
}
point cro[];
int main(){
//freopen("D:\\INPUT.txt","r",stdin);
int n,J;
int i;
queue<int> q;
scanf("%d %d",&n,&J);
point *cro=new point[n];
for(i=;i<n;i++){
scanf("%d %d",&cro[i].x,&cro[i].y);
cro[i].dis=getdis(,,cro[i].x,cro[i].y);
}
if(7.5+J>=){
printf("Yes\n");
return ;
}
for(i=;i<n;i++){
if(cro[i].dis<=7.5){
cro[i].vis=true;//无效点
}
else if(cro[i].dis<=7.5+J){//在弹跳范围内,收集
q.push(i);
cro[i].vis=true;
}
}
int curnum,x,y;
while(!q.empty()){
curnum=q.front();
q.pop();
x=cro[curnum].x;
y=cro[curnum].y;
if(abs(x)+J>=||abs(y)+J>=){//可以到达岸边
printf("Yes\n");
return ;
}
for(i=;i<n;i++){
if(!cro[i].vis){
cro[i].dis=getdis(x,y,cro[i].x,cro[i].y);
if(cro[i].dis<=J){
q.push(i);
cro[i].vis=true;
}
}
}
}
printf("No\n");
return ;
}
pat05-图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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- 通过ajax把json对象传入后台
一.前台ajax部分 function icheckDelete(url){ var parms = { list : array //这是个数组 }; $.ajax({ dataType: &quo ...
- MapReduce-自定义 InputFormat 生成 SequenceFile
Hadoop 框架自带的 InputFormat 类型不能满足所有应用场景,需要自定义 InputFormat 来解决实际问题. 无论 HDFS 还是 MapReduce,在处理小文件时效率都非常低, ...
- datetime问题
DateUtil.format(DateTime.now(), DatePattern.NORM_DATE_PATTERN);. 此方法将现在时间转为yy--mm--dd格式 mysql中日期运算 ...
- fabric java chaincode 开发
链码的开发不部分参考官网demo即可. 本文不会详细介绍开发过程 笔者启动的是一个gradle工程,也就是jar包管理使用的是gradle. chaincode 源码: /* Copyright IB ...
- C/C++ 遇到0xcccccccc访问冲突
最近一直在纠结这个问题. 最近写代码,总是遇到这个问题,一旦遇到这个问题,以前好使的代码也就不好使了.很费解,上网搜集了下资料.... 这个0xcccccccc是DEBUG模式下,编译器为没有初始化的 ...
- 7、OpenCV Python 高斯模糊
__author__ = "WSX" import cv2 as cv import numpy as np #高斯模糊 基于权重(卷积) #高斯模糊 去燥效果很好 #高斯模糊 d ...
- 平衡树学习笔记(2)-------Treap
Treap 上一篇:平衡树学习笔记(1)-------简介 Treap是一个玄学的平衡树 为什么说它玄学呢? 还记得上一节说过每个平衡树都有自己的平衡方式吗? 没错,它平衡的方式是......rand ...
- Codeforces Round #533 (Div. 2)题解
link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...
- CF581B Luxurious Houses 模拟
The capital of Berland has n multifloor buildings. The architect who built up the capital was very c ...
- kuangbin专题十六 KMP&&扩展KMP HDU2594 Simpsons’ Hidden Talents
Homer: Marge, I just figured out a way to discover some of the talents we weren’t aware we had. Marg ...