pat06-图4. Saving James Bond - Hard Version (30)
06-图4. Saving James Bond - Hard Version (30)
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 a shortest path to reach one of the banks. The length of a path is the number of jumps that James has to make.
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, if James can escape, output in one line the minimum number of jumps he must make. Then starting from the next line, output the position (x, y) of each crocodile on the path, each pair in one line, from the island to the bank. If it is impossible for James to escape that way, simply give him 0 as the number of jumps. If there are many shortest paths, just output the one with the minimum first jump, which is guaranteed to be unique.
Sample Input 1:
- 17 15
- 10 -21
- 10 21
- -40 10
- 30 -50
- 20 40
- 35 10
- 0 -10
- -25 22
- 40 -40
- -30 30
- -10 22
- 0 11
- 25 21
- 25 10
- 10 10
- 10 35
- -30 10
Sample Output 1:
- 4
- 0 11
- 10 21
- 10 35
Sample Input 2:
- 4 13
- -12 12
- 12 12
- -12 -12
- 12 -12
Sample Output 2:
- 0
本题测试点5是从小岛范围内可以直接跳到岸边。
- #include<cstdio>
- #include<algorithm>
- #include<iostream>
- #include<cstring>
- #include<queue>
- #include<stack>
- #include<cmath>
- #include<string>
- using namespace std;
- #define R 7.5
- struct point
- {
- int x,y,last;
- bool vis;
- point()
- {
- vis=false;
- }
- point(int num)
- {
- vis=false;
- last=num;
- }
- };
- point p[];
- queue<int> q;
- double getdis(int x1,int y1,int x2,int y2)
- {
- int x=x1-x2;
- int y=y1-y2;
- return sqrt(x*x+y*y);
- }
- int abs(int a)
- {
- return a>?a:-a;
- }
- int main()
- {
- //freopen("D:\\INPUT.txt","r",stdin);
- int n,J;
- scanf("%d %d",&n,&J);
- int i,level=,last=-,tail;
- for(i=; i<n; i++)
- {
- scanf("%d %d",&p[i].x,&p[i].y);
- p[i].last=i;
- }
- if(R+J>=){//小岛内直接跳到岸边
- printf("1\n");
- return ;
- }
- for(i=; i<n; i++)
- {
- if(getdis(,,p[i].x,p[i].y)<=R){//无效点
- p[i].vis=true;
- continue;
- }
- if(R+J>=getdis(,,p[i].x,p[i].y))
- {
- q.push(i);
- p[i].vis=true;
- last=i;
- if(abs(p[i].x)+J>=||abs(p[i].y)+J>=)
- {
- printf("2\n");
- printf("%d %d\n",p[i].x,p[i].y);
- return ;
- }
- }
- }
- if(last==-){//一开始就没有可以跳的点
- printf("0\n");
- return ;
- }
- int cur,firstj=J+,fitp,count=;
- while(!q.empty())
- {
- cur=q.front();
- q.pop();
- for(i=; i<n; i++)
- {
- if(!p[i].vis&&J>=getdis(p[cur].x,p[cur].y,p[i].x,p[i].y))
- {//没有入队并且符合要求
- p[i].vis=true;
- q.push(i);//入队
- p[i].last=cur;
- tail=i;
- if(abs(p[i].x)+J>=||abs(p[i].y)+J>=)
- {
- int now=i;
- while(p[now].last!=now){
- now=p[now].last;
- }
- if(getdis(,,p[now].x,p[now].y)-R<firstj){
- firstj=getdis(,,p[now].x,p[now].y)-R;
- fitp=i;
- count=level+;
- }
- }
- }
- }
- if(cur==last){
- level++;//向下一层进发
- last=tail;
- }
- if(level==count){
- break;
- }
- }
- stack<int> s;
- if(count)
- {
- count++;
- while(p[fitp].last!=fitp)
- {
- s.push(fitp);
- fitp=p[fitp].last;
- }
- s.push(fitp);
- }
- printf("%d\n",count);
- while(!s.empty())
- {
- printf("%d %d\n",p[s.top()].x,p[s.top()].y);
- s.pop();
- }
- return ;
- }
pat06-图4. Saving James Bond - Hard Version (30)的更多相关文章
- PTA 07-图5 Saving James Bond - Hard Version (30分)
07-图5 Saving James Bond - Hard Version (30分) This time let us consider the situation in the movie ...
- 07-图5 Saving James Bond - Hard Version (30 分)
This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...
- Saving James Bond - Easy Version (MOOC)
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...
- pat05-图2. Saving James Bond - Easy Version (25)
05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...
- Saving James Bond - Hard Version
07-图5 Saving James Bond - Hard Version(30 分) This time let us consider the situation in the movie &q ...
- Saving James Bond - Easy Version 原创 2017年11月23日 13:07:33
06-图2 Saving James Bond - Easy Version(25 分) This time let us consider the situation in the movie &q ...
- PAT Saving James Bond - Easy Version
Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...
- 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 ...
- PTA 06-图2 Saving James Bond - Easy Version (25分)
This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...
随机推荐
- sqlserver快速删除整个表数据
--删除整个表数据 SET STATISTICS TIME ON; DECLARE @Timer DATETIME = GETDATE(); TRUNCATE TABLE LOG_DEBUG_ERRO ...
- nginx 部署 .net core 获取的客户端ip为127.0.0.1
采用nginx和.net core 部署一套api接口到服务器上,发现获取到的ip地址为127.0.0.1 经过检查发现,需要在nginx配置上以下参数 proxy_set_header Host $ ...
- [Algorithm]树与二叉树
一.树与二叉树相关算法 1.二叉树按顺序结构存储,求编号为i和j的两个结点的最近公共祖先结点的值 1 ElemType CommonAncestor( SeqTree T, int i, int j ...
- day05.1-文件归档与压缩
>:覆盖式修改文件内容.如: a). cat /etc/passwd > new_pass.txt(将/etc/passwd中的内容覆盖式复制到new_pass.txt中,若n ...
- json解析(自动判断是jsonArray和jsonObject)
因为想做一个接口自动化框架,已经实现了接口的访问和连接及获取接口返回的json数据,但json数据的解析是个麻烦的事情,所以写一个简单的版本记录一下.后续会进行优化,实现方法分离以及自动识别循环解析返 ...
- 关于vue项目多页面的配置
基于vue2.0生成项目,一段时间都在找如何配置成多个页面的.网上有这样的例子相对也是比较详细的,但是还是有些许不一样的地方的.所以,我还是记录下来,当然我也是参考了网上的资料的. 当然先来个vue的 ...
- 基于XML的类的属性的装配
基于XML的属性装配 1.手动装配 <!-- 属性的装配:手动装配 --> <bean id="userService" class="com.neue ...
- 【NOIP 2009】靶形数独
题目描述 小城和小华都是热爱数学的好学生,最近,他们不约而同地迷上了数独游戏,好胜的他们想用数独来一比高低.但普通的数独对他们来说都过于简单了,于是他们向 Z 博士请教,Z 博士拿出了他最近发明的“靶 ...
- linux 内核的 switch_to原理
switch_to:这是一个宏,有三个参数prev,next,last 局部变量prev,next:指向进程描述符的内存地址 首先明确的是:last和prev是同一个,用last只是为了理解方便,完全 ...
- shared_ptr 和auto_ptr智能指针
shared_ptr:计数的智能指针 它是一个包装了new操作符在堆上分配的动态对象,但它实现的是引用计数型的智能指针 ,可以被自由地拷贝和赋值,在任意的地方共享它,当没有代码使用(引用计数为0)它时 ...