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. HashMap源码原理

    HashMap源码解析(负载因子,树化策略,内部hash实现,resize策略) 内部属性: 负载因子: final float loadFactor(默认为0.75f) 实际容量: int thre ...

  2. Kafka分布式的消息顺序

    Kafka分布式的单位是partition,同一个partition用一个write ahead log组织,所以可以保证FIFO的顺序.不同partition之间不能保证顺序. 但是绝大多数用户都可 ...

  3. ubuntu ufw相关命令

    引自:http://www.cnblogs.com/jiangyao/archive/2010/05/19/1738909.html 就这句话就够了,下面的可以不看 sudo  ufw enable| ...

  4. 记一次Spring boot集成mybatis错误修复过程 Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

    最近自己写了一份代码签入到github,然后拉下来运行报下面的错误 Error starting ApplicationContext. To display the conditions repor ...

  5. VS 对话框控件的Tab顺序问题

    我们先来直观的看看各个控件的Tab顺序吧.打开“Resource View”视图,然后在资源中找到对话框IDD_ADDITION_DIALOG,双击ID后中间客户区域出现其模板视图.在主菜单中选择“F ...

  6. Vue学习之基础及部分指令小结(一)

    一.理解MVC和MVVM的关系: MVC:Model View Controller (模型 视图 控制器) 分别为:业务逻辑.界面.用来调度View和Model层 MVVM:Model View V ...

  7. Python之路(第四十二篇)线程相关的其他方法、join()、Thread类的start()和run()方法的区别、守护线程

    一.线程相关的其他方法 Thread实例对象的方法 # isAlive(): 返回线程是否活动的. # getName(): 返回线程名. # setName(): 设置线程名. ​ threadin ...

  8. RxJS——可观察的对象(Observable)

    可观察的(Observable) 可观察集合(Observables)是多值懒推送集合.它们填补了下面表格的空白: SINGLE MULTIPLE Pull Function Iterator Pus ...

  9. python json dumps与loads

    json.dumps() 是将一个Python数据结构转换为一个JSON编码的字符串 json.loads() 是将一个JSON编码的字符串转换为一个Python数据结构   一般要求当要字符串通过l ...

  10. 解锁 redis 锁的正确姿势

    redis 是 php 的好朋友,在 php 写业务过程中,有时候会使用到锁的概念,同时只能有一个人可以操作某个行为.这个时候我们就要用到锁.锁的方式有好几种,php 不能在内存中用锁,不能使用 zo ...