日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

06-图2 Saving James Bond - Easy Version

發布時間:2024/1/17 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 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代表一種拯救方案,只要存在一種方案即可獲救 */ #include <cstdio> #include <cmath> #include <cstdlib>const double ISLAND_RADIUS = 15.0 / 2; //孤島半徑 const double SQUARE_SIZE = 100.0; //湖(正方形)的大小 const int N = 110; //鱷魚(點)的最大數 typedef struct Point {double x, y; } Position;Position P[N]; bool Visited[N]; int n; double d;void Save007(); bool DFS(int V); bool FirstJump(int V); bool Jump(int V1, int V2); bool IsSave(int V);int main() {scanf("%d%lf", &n, &d);for (int i = 0; i < n; i++)scanf("%lf%lf", &(P[i].x), &(P[i].y));for (int i = 0; i < n; i++)Visited[i] = false;Save007();return 0; }void Save007() {bool IsSave = false;for (int i = 0; i < n; i++){if (!Visited[i] && FirstJump(i)){IsSave = DFS(i);if (IsSave)break;}}if (IsSave)printf("Yes\n");elseprintf("No\n"); }bool DFS(int V) {Visited[V] = true;bool answer = false;if (IsSave(V))return true;for (int i = 0; i < n; i++){if (!Visited[i] && Jump(V, i))answer = DFS(i);if (answer)break;}return answer; }bool IsSave(int V) {return (abs(P[V].x) >= 50 - d)|| (abs(P[V].y) >= 50 - d); }bool FirstJump(int V) {return sqrt(P[V].x * P[V].x + P[V].y * P[V].y)<= d + ISLAND_RADIUS; }bool Jump(int V1, int V2) {return sqrt((P[V1].x - P[V2].x) * (P[V1].x - P[V2].x) +(P[V1].y - P[V2].y) * (P[V1].y - P[V2].y))<= d; }

?

轉載于:https://www.cnblogs.com/llhthinker/p/4844990.html

總結

以上是生活随笔為你收集整理的06-图2 Saving James Bond - Easy Version的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。