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
#include<cstdio>
#include<queue>
#include<stack>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = ;
const int minLen = - 15.0/; struct Point
{
int x,y;
}point[maxn]; int path[maxn] = {};
bool vis[maxn] = {};
int n,d; void BFS();
void init(int b[]);
bool cmp(int x,int y);
int FirstJump(int v);
bool isSafe(int v);
bool Jump(int v1,int v2); int main()
{
scanf("%d%d",&n,&d);
for (int i = ; i < n; i++)
{
scanf("%d%d",&point[i].x,&point[i].y);
} if (d >= minLen)
{
printf("1\n");
}
else
{
BFS();
}
return ;
} void BFS()
{
int b[maxn];
init(b);
sort(b,b+n,cmp); queue<int> q;
int last;
int tail;
int step = ; for (int i = ; i < n; i++)
{
if(FirstJump(b[i]))
{
q.push(b[i]);
vis[b[i]] = true;
last = b[i];
}
} while(!q.empty())
{
int now = q.front();
q.pop(); if (isSafe(now))
{
int k =;
stack<int> s;
cout << step << endl; while (k < step)
{
s.push(now);
now = path[now];
k++;
} while (!s.empty())
{
now = s.top();
s.pop();
cout << point[now].x << " " << point[now].y << endl;
}
return;
} for (int i = ; i < n; i++)
{
if (!vis[i] && Jump(now,i))
{
q.push(i);
vis[i] = true;
tail = i;
path[i] = now;
}
} if (last == now)
{
last = tail;
step++;
}
} if (q.empty())
{
cout << "" << endl;
}
} void init(int b[])
{
for (int i = ; i < n; i++)
{
b[i] = i;
}
} bool cmp(int x,int y)
{
return FirstJump(x) < FirstJump(y);
} int FirstJump(int v)
{
int dis = pow(point[v].x,) + pow(point[v].y,);
int dis_Jump = pow(15.0/ + d,);
if (dis <= dis_Jump)
{
return dis;
}
else
{
return ;
}
} bool isSafe(int v)
{
int dis_safe = - d;
return abs(point[v].x) >= dis_safe || abs(point[v].y) >= dis_safe;
} bool Jump(int v1,int v2)
{
int dis_x = pow(point[v1].x-point[v2].x, );
int dis_y = pow(point[v1].y-point[v2].y, );
if (dis_x + dis_y <= d*d)
{
return true;
}
else
{
return false;
}
}


07-图5 Saving James Bond - Hard Version (30 分)的更多相关文章

  1. 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 ...

  2. pat06-图4. Saving James Bond - Hard Version (30)

    06-图4. Saving James Bond - Hard Version (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Saving James Bond - Easy Version (MOOC)

    06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...

  7. pat05-图2. Saving James Bond - Easy Version (25)

    05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...

  8. Saving James Bond - Hard Version

    07-图5 Saving James Bond - Hard Version(30 分) This time let us consider the situation in the movie &q ...

  9. PAT Saving James Bond - Easy Version

    Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...

随机推荐

  1. 【已解決】谷歌浏览器如何清理缓存(cookie)

    清除缓存快捷键 Ctrl+Shift+Delete

  2. Vert.x Web

    https://vertx.io/docs/vertx-web/java/ Vert.x-Web是一组用于使用Vert.x构建Web应用程序的构建块.将其视为瑞士军刀,用于构建现代,可扩展的网络应用程 ...

  3. [大数据学习研究] 错误排查,Hadoop集群部分DataNode不能启动

    错误现象 不知道什么原因,今天发现我的hadoop集群启动后datanode只有一台了,我的集群本来有三台的,怎么只剩一台了呢? 用jps命令检查一下,发现果然有两台机器的DataNode没有启动. ...

  4. vue打包后页面显示空白但是不报错

    在使用vue打包的时候页面显示空白,并且控制台不报错 设置vue-router的时候mode设置为history模式了,这种模式要有后台的配合,一般还是使用哈希模式就不会出现页面空白了.

  5. 11、多行文本最后一行显示省略号并截取文本字数(vue)

    1.首先通过css实现多行文本显示省略号: { height: 45px; display: -webkit-box; -webkit-box-orient: vertical; -webkit-li ...

  6. 字符串转换成float和double类型

    double strtod(const char *nptr, char **endptr); float strtof(const char *nptr, char **endptr); long ...

  7. iOS之Category关联属性

    Objective-C /** 原文件 */ // Person.h #import <Foundation/Foundation.h> @interface Person : NSObj ...

  8. 深入理解 ValueTask

    深入理解 ValueTask .NET Framework 4 里面的命名空间为 System.Threading.Tasks的 Task 类.这个类以及它派生的 Task<TResult> ...

  9. AR-运行自动开票主程序报错

    问题: 在AR运行自动开票主程序时出现如下错误提示: 错误日志: raagsp()+ 当前的系统时间为 12-09-2014 07:23:58 raagsp()- 当前的系统时间为 12-09-201 ...

  10. 《linux就该这么学》课堂笔记09 存储结构、磁盘划分

    Linux一切都是文件 "/"为根目录(万物起始)  **挂载后要想永久生效,需要修改开机启动项 vim /etc/fstab