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 (≤), the number of crocodiles, and D, the maximum distance that James could jump. Then N lines follow, each containing the ( 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 ( 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<iostream>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = ;
const int minLen = - /;
struct Pointer{
int x,y;
}point[maxn];
int path[maxn] = {-};
bool visited[maxn] = {false};
int d[maxn],n,m; void init(){
for(int i = ; i < n; i++) d[i] = i;
} bool Jump(int u,int v){
int d1 = pow(point[u].x - point[v].x,);
int d2 = pow(point[u].y - point[v].y,);
int r = m * m;
if(r >= d1 + d2) return true;
else return false;
} int firstJump(int v){
int d1 = pow(point[v].x,);
int d2 = pow(point[v].y,);
int r = (m+7.5)*(m+7.5);
if(r >= d1 + d2) return d1+d2;
else return ;
} bool isSafe(int x) { /* 判断从当前点能否跳到岸上 */
if ((point[x].x - m <= -) || (point[x].x + m >= ) || (point[x].y - m <= -) || (point[x].y + m >= ))
return true;
return false;
} bool cmp(int x,int y){
return firstJump(d[x]) < firstJump(d[y]);
} void BFS() { /* 用bfs来判断最少要踩几个小鳄鱼才能上岸 */
int b[];
queue<int>q;
/* 将第一步能踩到的鳄鱼按距离从小到大的顺序进队列~ 因为输出结果要保证在踩的鳄鱼数量相等的情况下 输出第一步距离最短的~~*/
for (int i = ; i < n; i++) {
b[i] = i;
}
sort(b, b + n, cmp); /* 按照第一步的距离排序~~~ */
int last;
for (int i = ; i < n; i++) {
if (firstJump(b[i])) { /* 能跳上去! */
q.push(b[i]);
visited[b[i]] = true; /* 指向当前层数最后一个数~ */
last = b[i];
}
}
int step = ; /* 记录最少要跳跃的次数 */
int tail;
while (!q.empty()) {
int p = q.front();
q.pop();
if (isSafe(p)) {
int k = ;
stack<int> s;
cout << step << endl;
while (k < step) {
//cout << point[p].x << " " << point[p].y << endl;
s.push(p);
p = path[p];
k++;
}
while (!s.empty()) {
p = s.top();
s.pop();
cout << point[p].x << " " << point[p].y << endl;
}
return;
}
for (int i = ; i < n; i++) {
if (!visited[i] && Jump(p, i)) { /* 没踩过并且能跳到 */
q.push(i);
path[i] = p; /* 记得当前进队节点的父节点~ */
visited[i] = true;
tail = i; /* 指向下一层的最后一个元素 */
}
}
if (last == p) { /* 即将进入下一层~ */
step += ;
last = tail;
}
}
if (q.empty()) { /* 如果队列为空 说明没跳出去啊~ */
cout << "" << endl;
}
} int main(){
scanf("%d%d",&n,&m);
init();
for(int i = ; i < n; i++){
scanf("%d%d",&point[i].x,&point[i].y);
}
if(m >= minLen){
printf("1\n");
return ;
}
BFS();
return ;
}

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

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

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

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

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

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

  7. Saving James Bond - Easy Version (MOOC)

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

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

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

  9. Saving James Bond - Hard Version

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

  10. PAT Saving James Bond - Easy Version

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

随机推荐

  1. 字符串解压缩类库(zip、GZIP、QuickLz、snappy、lzf、jzlib)介绍

    1.ZIP. GZIP  计算机文件压缩算法,JDK中java.util.zip.*中实现.主要包括ZipInputStream/ ZipOutputStream.GZipInputStream/Zi ...

  2. android 获取sharedpreference的三种方法的区别

    1. public SharedPreferences getPreferences (int mode) 通过Activity对象获取,获取的是本Activity私有的Preference,保存在系 ...

  3. day17-jdbc 7.Statement介绍

    SQL语句:DML.DQL.DCL.DDL.DML和DQL是用的最多的.DCL和DDL用的很少. 程序员一般是操作记录,创建一表很少. package cn.itcast.jdbc; import c ...

  4. unity3d 5.6参考手册

    http://www.vfkjsd.cn/unity3d/Manual/index.html http://www.vfkjsd.cn/unity/unity3d.html

  5. Eigen介绍及简单使用

    博客转载自:https://blog.csdn.net/fengbingchun/article/details/47378515 Eigen是可以用来进行线性代数.矩阵.向量操作等运算的C++库,它 ...

  6. java中字符串的存储

    在java中,不同的字符串赋值方法,其所在的地址可能不同也就导致,两个字符串的值看似相等可是在s1==s2操作时,其结果返回的却是false 例: String s1 = "Programm ...

  7. CF 1025C Plasticine zebra

    昨晚忘记判只有一个字符的情况fst了呜呜呜 挺有趣的题,昨晚连刚带猜弄出结论 考虑答案的取值,最优答案可能是一个后缀,或者是一个前缀,或者是一个后缀加上前缀 那么翻转之后最优答案的可选值就有了1的前缀 ...

  8. 树莓派研究笔记(9)-- 树莓派SPI连接TFT屏幕

    HDMI连接和树莓派专用连接的接口的屏幕都太贵了,为了节约成本,现在国内大多数还是TFT屏幕. 树莓派可以激活SPI接口,通过代码驱动TFT屏幕的显示.这样利用树莓派zero 打造小型的游戏平台可以大 ...

  9. Qemu虚拟机 玩树莓派最新版系统 (截止2017-04-10)

    Qemu虚拟机可以玩 树莓派,大家都知道了吧.可是网上的教程好老,都是2012年的.我按照教程下载了最新版版本的树莓派系统怎么也跑不起来. 研究了好久,终于找到一个简单的方法,特意分享出来.转载请注意 ...

  10. Java中常见设计模式面试

    一.设计模式的分类 总体来说设计模式分为三大类: 创建型模式,共五种:工厂方法模式.抽象工厂模式.单例模式.建造者模式.原型模式. 结构型模式,共七种:适配器模式.装饰器模式.代理模式.外观模式.桥接 ...