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

題目地址

https://pta.patest.cn/pta/test/16/exam/4/question/672

?

5-10?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?NN?(\le 100100), the number of crocodiles, and?DD, the maximum distance that James could jump. Then?NN?lines follow, each containing the?(x, y)(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


比較簡單的一個題,找所有可以起跳的點設為start,可以上岸的點設為finish
然后把在跳躍距離內的點連起來
遍歷所有start,如果路徑上遇到finish,那么是可以上岸的

/*
評測結果
時間	結果	得分	題目	編譯器	用時(ms)	內存(MB)	用戶
2017-07-02 00:53	答案正確	25	5-10	gcc	2	1	
測試點結果
測試點	結果	得分/滿分	用時(ms)	內存(MB)
測試點1	答案正確	7/7	2	1
測試點2	答案正確	6/6	1	1
測試點3	答案正確	3/3	2	1
測試點4	答案正確	3/3	2	1
測試點5	答案正確	3/3	1	1
測試點6	答案正確	3/3	1	1
*/
#include<stdio.h>
#include<math.h>
#define MAX_CROCODILE 100
#define CENTRAL_ISLAND_R 7.5
#define BORDER 50
#define TRUE 1
#define FALSE 0struct tCrocoVertex
{int x;int y;int start;int finish;
} gNodeTab[MAX_CROCODILE];int gMatrix[MAX_CROCODILE][MAX_CROCODILE];
int gVisitedFlag[MAX_CROCODILE];
int gCanBeSavedFlag=FALSE;void FindStartAndFinishNode(int N,int jumpDistance)
{int i,distSquare;float startDistSquare=(jumpDistance+CENTRAL_ISLAND_R)*(jumpDistance+CENTRAL_ISLAND_R);for(i=0;i<N;i++){distSquare=(gNodeTab[i].x)*(gNodeTab[i].x)+(gNodeTab[i].y)*(gNodeTab[i].y);if(distSquare<=startDistSquare){gNodeTab[i].start=TRUE;}gNodeTab[i].finish=	(abs(gNodeTab[i].x-BORDER)<=jumpDistance ||abs(gNodeTab[i].x+BORDER)<=jumpDistance ||abs(gNodeTab[i].y-BORDER)<=jumpDistance ||abs(gNodeTab[i].y+BORDER)<=jumpDistance)?TRUE:FALSE;}
}void BuildMatrix(int N,int jumpDistance)
{int i,j;int distSquare,jumpDistanceSquare;jumpDistanceSquare=jumpDistance*jumpDistance;for(i=0;i<N;i++)for(j=0;j<i;j++){distSquare=	(gNodeTab[i].x-gNodeTab[j].x)*(gNodeTab[i].x-gNodeTab[j].x)+(gNodeTab[i].y-gNodeTab[j].y)*(gNodeTab[i].y-gNodeTab[j].y);if(distSquare<=jumpDistanceSquare){gMatrix[i][j]=TRUE;gMatrix[j][i]=TRUE;}}
}void DFS(int x,int N)
{if(gCanBeSavedFlag==TRUE)return;int i;if(gNodeTab[x].finish==TRUE)gCanBeSavedFlag=TRUE;gVisitedFlag[x]=TRUE;for(i=0;i<N;i++){if(gMatrix[x][i]==TRUE && gVisitedFlag[i]==FALSE)DFS(i,N);}
}
void DBG_ShowStatus(N)
{int i,j;for(i=0;i<N;i++){printf("ID:%d,x:%d,y:%d,start:%d,finish:%d,visited:%d\n",i,gNodeTab[i].x,gNodeTab[i].y,gNodeTab[i].start,gNodeTab[i].finish,gVisitedFlag[i]);}for(i=0;i<N;i++){for(j=0;j<N;j++)printf("%d ",gMatrix[i][j]);printf("\n");}}
int main()
{int i,N,D;scanf("%d %d",&N,&D);for(i=0;i<N;i++){scanf("%d %d",&gNodeTab[i].x,&gNodeTab[i].y);}FindStartAndFinishNode(N,D);BuildMatrix(N,D);for(i=0;i<N;i++){if(gCanBeSavedFlag==TRUE)break;if(gNodeTab[i].start==TRUE && gVisitedFlag[i]==FALSE)DFS(i,N);}if(gCanBeSavedFlag==TRUE)printf("Yes");elseprintf("No");
// 	DBG_ShowStatus(N);
}

  

轉載于:https://www.cnblogs.com/gk2017/p/7141016.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/252356.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/252356.shtml
英文地址,請注明出處:http://en.pswp.cn/news/252356.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Ubuntu16.04上安裝kitti2bag

kitti2bag是一個可以將kitti數據集轉換為bag文件的工具&#xff0c;可以直接通過pip進行安裝。由于kitti2bag中使用到ros&#xff0c;所以安裝時你使用的python版本應該是2.7的因為ros只有在Python2.7時才能正常工作。比如說我&#xff0c;我安裝了conda&#xff0c;在conda中安…

Nginx之windows下搭建

去nginx.org下載nginx 以nginx-1.8.1為例解壓到D盤nginx-1.8.1目錄 假設NGINX_HOME為D:\nginx-1.8.1 3種啟動途徑&#xff1a; 一、雙擊nginx.exe圖標&#xff0c;可見黑窗口一閃而過&#xff0c;啟動完畢。 二、命令行到nginx目錄&#xff0c;輸入nginx啟動。&#xff08;注&a…

單片機錯誤筆記

記錄下使用單片機過程中的一些錯誤&#xff0c;便于以后查詢&#xff1a; 單片機型號&#xff1a;STC15F2K60S2 晶振&#xff1a;18.432 報錯代碼&#xff1a; *** WARNING L1: UNRESOLVED EXTERNAL SYMBOLSYMBOL: REC_DAT1MODULE: .\Objects\usart.obj (USART) …

軟件開發記錄03

今天我完成了軟件設置&#xff0c;預算列表&#xff0c;添加預算的頁面布局。 &#xff08;1&#xff09;軟件設置 <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android"…

395. Longest Substring with At Least K Repeating Characters

題目要求 Find the length of the longest substring T of a given string (consists of lowercase letters only) such that every character in T appears no less than k times.Example 1:Input: s "aaabb", k 3Output: 3The longest substring is "aaa&qu…

UICollectionView 具體解說學習

UICollectionView 和UITableView非常像,是APPLE公司在iOS 6后推出的用于處理圖片這類UITableView 布局困難的控件,和UITableView 一樣,它也有自己的Datasource和delegate。以下具體說下像這種方式的效果. 首先來看看UICollectionView 的DataSource。protocol UICollectionView…

70.文件異常

ferror檢測文件異常perror提示文件錯誤信息clearerr清除異常,讓文件指針回到開頭完整代碼 1 #define _CRT_SECURE_NO_WARNINGS2 #include<stdio.h>3 #include<stdlib.h>4 //perror提示文件錯誤信息5 //ferror檢測文件異常6 //clearerr清除異常,讓文件指針回到開頭…

ServiceNow 中關于UI Action 在portal端的使用

在 portal端是可以使用Form和UI Action的&#xff0c;例如&#xff1a;var data.f $sp.getForm()&#xff1b;//需要添加上相應參數在開箱組件Form的Server script中就有如下代碼&#xff1a;data.f $sp.getForm(data.table, data.sys_id, data.query, data.view);data.f對象中…

特殊密碼鎖

總時間限制: 1000ms內存限制: 1024kB描述有一種特殊的二進制密碼鎖&#xff0c;由n個相連的按鈕組成&#xff08;n<30&#xff09;&#xff0c;按鈕有凹/凸兩種狀態&#xff0c;用手按按鈕會改變其狀態。 然而讓人頭疼的是&#xff0c;當你按一個按鈕時&#xff0c;跟它相鄰…

系統安全題目(二)

1、在 php mysql apache 架構的web服務中輸入GET參數 index.php?a1&a2&a3 服務器端腳本 index.php 中$GET[a] 的值是&#xff1f;正確答案: C A 1B 2C 3D 1,2,3 2、以下哪些不是CSRF漏洞的防御方案&#xff1f;正確答案: D A 檢測HTTPrefererB 使用隨機tokenC 使用驗…

轉發和重定向的區別?

實際發生位置不同&#xff0c;地址欄不同 轉發是發生在服務器的 轉發是由服務器進行跳轉的&#xff0c;細心的朋友會發現&#xff0c;在轉發的時候&#xff0c;瀏覽器的地址欄是沒有發生變化的&#xff0c;在我訪問Servlet111的時候&#xff0c;即使跳轉到了Servlet222的頁面&a…

BZOJ3795 : 魏總刷DP

對于HARD&#xff1a; 需要滿足$ku[i]\times k\leq Tlate[i]$。 對于EASY&#xff1a; 需要滿足$ku[i]\times k\leq T-rest[i]$。 故對于HARD&#xff0c;設$a[i]-late[i]$&#xff0c;對于EASY&#xff0c;設$a[i]rest[i]$&#xff0c;并將所有題目的$u[i]$都$1$。 那么需要滿…

信息學競賽相關優秀文章合集[持續更新]

線段樹詳解 &#xff08;原理&#xff0c;實現與應用&#xff09;可持久化線段樹 簡介 運用伸展樹解決數列維護問題.pdfSplay 學習筆記&#xff08;一&#xff09;Splay 學習筆記&#xff08;二&#xff09;Splay 學習筆記&#xff08;三&#xff09; 請要相信我&#xff0c;30…

ceres-solver學習筆記

前一段時間總有一個想法&#xff0c;那就是&#xff0c;我只直到視覺slam是遠遠不夠的&#xff0c;激光slam仍然是一個比較穩妥的技術&#xff0c;好落地&#xff0c;應用廣泛&#xff0c;我想著&#xff0c;如果我學會了會大大增加自己的核心競爭力&#xff0c;所以我抽時間開…

幾款常見的視頻格式轉換器

在短視頻占半壁江山的時候&#xff0c;關于體積、格式等成了困擾人們的因素&#xff0c;視頻太大不利于傳播&#xff0c;比如微信里就限制了傳輸的大小不得超過20M&#xff0c;所以其實說起來工作上QQ的性能遠超微信。今天這里小編給大家總結幾款常用的視頻轉換器&#xff0c;希…

PHP Shell生成工具Weevely

PHP Shell生成工具WeevelyWeevely是一款模擬Telnet連接的PHP Shell工具。它不提供網頁形式的接口&#xff0c;而是提供一個命令形式的終端。滲透測試人員首先使用該工具生成對應的PHP網頁。然后&#xff0c;將該網頁上傳到目標Web服務器上。滲透人員就可以在終端連接該頁面&…

ceres學習之平面擬合

背景&#xff1a;orb-slam2最終保存的軌跡形成的平面是一個傾斜的&#xff0c;這個與相機初始化位置有關&#xff0c;但是有些時候&#xff0c;我們需要的是一個2d的軌跡的試圖&#xff0c;直接將軌跡向某一個平面投影的話。 得到的估計是失真的&#xff0c;所以我們需要對軌跡…

二維樹狀數組模板(區間修改+區間查詢)

二維樹狀數組模板(區間修改區間查詢) 例題&#xff1a;JOIOI上帝造題的七分鐘 一共兩種操作&#xff1a; \(L\ x_1\ y_1\ x_2\ y_2\ d\)&#xff1a;把\((x_1,y_1)\)&#xff0c;\((x_2,y_2)\)這個矩形內所有元素加\(d\)。\(k\ x_1\ y_1\ x_2\ y_2\)&#xff1a;查詢\((x_1,y_1…

egg(110,111,112)--egg之微信支付

微信支付前的準備工作 準備工作 準備工作&#xff1a;個體工商戶、企業、政府及事業單位。需要獲取內容 appid&#xff1a;應用 APPID&#xff08;必須配置&#xff0c;開戶郵件中可查看&#xff09;MCHID&#xff1a;微信支付商戶號&#xff08;必須配置&#xff0c;開戶郵件中…

解決圖片跨域問題

var imgs new Image(); imgs.crossOrigin "Anonymous"; //注意存放順序 imgs.src "http://192.168.0.107/ZHCX/CGZSIMG/1.jpg"; imgs.onload function () { var canvas document.createElement(canvas); canvas.width imgs.width; canvas.height i…