7-10 Saving James Bond - Easy Version

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

这道题考察的主要是图的遍历-DFS的应用,需要注意的是Bond的第一跳与之后的其他跳不同,主要为所形成的圆的半径要加上湖中心岛的半径;其次,Bond的第一跳可能有多种选择,这些选择都有可能会产生逃生路径,所以使用DFS进行遍历的时候要遍历图中所有的连通集。具体代码实现为:

#include
#include

#define YES 1
#define NO 0

struct coordinate{  //鳄鱼坐标 
	int x;
	int y;
}crocodile[105];

int N,D;
int visited[105] = {0};  //标志某一个鳄鱼坐标是否被访问过,=0未被访问过 

void Save007();

int main()
{
	int i;
	
	scanf("%d %d",&N,&D);  //输入鳄鱼数量及007可以跳跃的最大距离
	for(i=0; i

 

你可能感兴趣的:(算法与数据结构,PTA,Saving,James,Bond,-,Easy,Versi)