您的位置:首页 > 其它

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

2017-10-28 20:58 387 查看

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 (≤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 <vector>
#define MAXV 100
struct node {
int x, y;
node(int _x, int _y) :x(_x), y(_y) {};
};
bool ans;
std::vector<node> v;
bool vis[MAXV][MAXV] = { false };

bool dis(node &n1, node &n2, int d) {
int tmp = (n1.x - n2.x)*(n1.x - n2.x) + (n1.y - n2.y)*(n1.y - n2.y);
return tmp <= d*d;
}

bool firstDis(node &n1, int d) {
double tmp = (n1.x-50)*(n1.x-50) + (n1.y-50)*(n1.y-50);
return tmp <= (d+7.5)*(d+7.5);
}

bool DFS(node &n, int d) {
vis[n.x][n.y] = true;
if(n.x <= d || n.y <= d || n.x >= (MAXV-d) || n.y >= (MAXV-d))
ans = true;
else {
for(auto i=v.begin(); i!=v.end(); ++i){
if((*i).x==n.x && (*i).y==n.y) continue;
if(!vis[(*i).x][(*i).y] && dis(n, *i, d)) {
ans = DFS(*i, d);
if(ans) break;
}
}
}
return ans;
}

void DFSTr(int x, int y, int d) {
bool res = false;
vis[x][y] = true;
for(auto i=v.begin(); i!=v.end(); ++i) {
if(!vis[(*i).x][(*i).y] && firstDis(*i, d)) {
res = DFS(*i, d);
if(res) break;
}
}
if(res) printf("Yes\n");
else printf("No\n");
}

int main() {
//freopen("text.txt", "r", stdin);
int n, d;
scanf("%d %d", &n, &d);
for (int i = 0; i<n; ++i) {
int tx, ty;
scanf("%d %d", &tx, &ty);
v.push_back(node(tx + 50, ty + 50));
}
DFSTr(50, 50, d);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: