06-圖2 Saving James Bond - Easy Version (25 分)
阿新 • • 發佈:2018-11-21
#include<cstdio> int const maxn=110; int N, D, answer; int visit[maxn]; struct point{ int x, y; }arr[maxn]; //三種結點 原點、鱷魚、岸邊 int Jump(int v, int i){ int flag; int a=arr[i].x-arr[v].x, b=arr[i].y-arr[v].y; int c=D*D; a=a*a; b=b*b; if(a+b<=c)flag=1; else flag=0; return flag; } int IsSafe(int v){//是否能夠到達岸邊 int a=arr[v].x, b=arr[v].y; if(a<0)a=-a; if(b<0) b=-b; if(a+D>=50||b+D>=50)return 1; else return 0; } int DFS(int v){ visit[v]=1; if(IsSafe(v))answer=1; else{ for(int i=0; i<N; i++){ if(visit[i]==0&&Jump(v, i)){ answer=DFS(i); if(answer==1)break; } } } return answer; } int FirstJump(int i){//每次起跳(島嶼半徑+跳躍能力) int flag; int a=arr[i].x, b=arr[i].y; a=a*a; b=b*b; double c=(15/2+D)*(15/2+D); if(a+b<=c)flag=1; else flag=0; return flag; } void Save007(){ for(int i=0; i<N; i++){ if(visit[i]==0&&FirstJump(i)){//原點周圍可以起跳的每個點 answer=DFS(i); if(answer)break; } } if(answer)printf("Yes\n"); else printf("No\n"); } int main(){ scanf("%d%d", &N, &D); for(int i=0; i<N; i++){ scanf("%d%d", &arr[i].x, &arr[i].y); } Save007(); return 0; }