06-図2 Saving James Bond-Easy Version(25分)
3237 ワード
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 centr of a lake filled with crocodiles.The he performed the most daring action to espe--hejumed ond to the head of the necrode!Before the animal realized what was happening、James jumed again one to the next big head…Finally he reached the bank before the last crocodile could bite hit
Asume that the lake is a 100 by 100 square one.Asume that the centr of the lake is at(0,0)and the Northeast coner at(50,50).The central islalalaland isa discentred at(0,0)with thethethethethethethethethethethethethethethethethethethethethethethethethethetheaaammmmthethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethetheaaaaaathe distance that James could jump、must tell him whether or not he can escape.
Input Specification:
Each input file contains one test case.Each case starts with a line containinining two positive integers N(≦100)、the number of crocodiles、and D、the maximdistancthJames could jum.The e Nfollinininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininatttttttttttttttttttinininininininininininininininininininininininアニメーション.
Output Specification:
For each test case,print in a line“Yes”if James can escape,or“No”if not.
Sample Input 1:
構想:構造樹組の保存点を使って、DFS遍歴;
注意点:小島には半径があります.この点を通るかどうかは変数でマークします.
Asume that the lake is a 100 by 100 square one.Asume that the centr of the lake is at(0,0)and the Northeast coner at(50,50).The central islalalaland isa discentred at(0,0)with thethethethethethethethethethethethethethethethethethethethethethethethethethetheaaammmmthethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethethetheaaaaaathe distance that James could jump、must tell him whether or not he can escape.
Input Specification:
Each input file contains one test case.Each case starts with a line containinining two positive integers N(≦100)、the number of crocodiles、and D、the maximdistancthJames could jum.The e Nfollinininininininininininininininininininininininininininininininininininininininininininininininininininininininininininininatttttttttttttttttttinininininininininininininininininininininininアニメーション.
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遍歴;
注意点:小島には半径があります.この点を通るかどうかは変数でマークします.
#include
#include
#define MaxNum 101
typedef struct Node Graph[MaxNum];
//
struct Node
{
int x, y;
int flag;//
};
int Jump(Graph G, int N, int D, int x, int y){
static int firstjump = 7.5;//
int i;
int result = 0;
if (abs(x) + D + firstjump >= 50 || abs(y) + D + firstjump >= 50){//
printf("Yes
");
return 1;
}
else
for (i = 0; i < N ; i++){
//
if ((D+firstjump)*(D+firstjump)>= (G[i].x - x)*(G[i].x - x)+ (G[i].y - y)*(G[i].y - y) && G[i].flag == 0){
G[i].flag = 1;
firstjump = 0;
result = Jump(G,N,D,G[i].x, G[i].y);//DFS
}
if (result == 1)
break;
}
return result;
}
int main(){
int N, D;
int i;
Graph G;
scanf("%d %d", &N, &D);
for(i = 0; i < N; i++){
scanf("%d %d",&G[i].x, &G[i].y);
}
for(i = 0; i < N; i++){
G[i].flag = 0;
}
if (!Jump(G, N, D, 0, 0))
printf("No
");
system("pause");
return 0;
}