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 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<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<stack>
using namespace std;
#define Maxnodenum 101
#define nolimitmax 100000
int flag=;//为了标志第一次拓展外层
vector<double> dist(Maxnodenum,nolimitmax);//为了记住跳到每个点的步数
vector<int> path(Maxnodenum,-);//为了记录路径
struct vertex{
int x;
int y;
};
struct graph{
int Nv;
int jump;
vertex G[Maxnodenum];
};
using Graph=graph*;
Graph BuildGraph(){
int v,x,y;
Graph gra=new graph();
cin>>gra->Nv>>gra->jump;
gra->G[].x=gra->G[].y=;
for(v=;v<=gra->Nv;v++)
{
cin>>gra->G[v].x>>gra->G[v].y;
}
return gra;
}
double distance(vertex n1,vertex n2){
return sqrt((n1.x-n2.x)*(n1.x-n2.x)+(n1.y-n2.y)*(n1.y-n2.y));
}
int saved(Graph gra,int v){
if(gra->G[v].x>=-gra->jump||gra->G[v].x<=-+gra->jump||gra->G[v].y>=-gra->jump||gra->G[v].y<=-+gra->jump)
{while(path[v]!=-){ if(path[v]==) { return ;}
v=path[v];
}
}
return ;
}
bool point(Graph gra,int v){
int x=gra->G[v].x; int y=gra->G[v].y;
if(x*x+y*y<=7.5*7.5||x>=||x<=-||y>=||y<=-)
{return false;}
else {return true;
}
}
void save(Graph gra){
if(gra->jump>=){
cout<<; return;
}
dist[]=; int v=,v1;
queue<int> q;
q.push(v);
while(!q.empty()){
v=q.front(); q.pop();
if(flag==){
for(v1=;v1<=gra->Nv;v1++){
if(point(gra,v1)&&distance(gra->G[],gra->G[v1])-7.5<=gra->jump&&path[v1]==-)
{ q.push(v1); dist[v1]=dist[v]+; path[v1]=v;}
}}
flag++;
if(flag!=){
for(v1=;v1<=gra->Nv;v1++)
if(point(gra,v1)&&distance(gra->G[v],gra->G[v1])<=gra->jump&&path[v1]==-)
{ q.push(v1); dist[v1]=dist[v]+; path[v1]=v;}}
}
int minstep=,laststep,v2;
stack<int> s;
for(v=;v<=gra->Nv;v++){
if(saved(gra,v)){
if(dist[v]<minstep){
minstep=dist[v];
laststep=v;
}else if(dist[v]==minstep){
v2=v;
while(path[v2]!=)
v2=path[v2];
v1=laststep;
while(path[v1]!=)
v1=path[v1];
laststep=distance(gra->G[],gra->G[v2])<distance(gra->G[],gra->G[v1])?v:laststep;
}}}
if(minstep!=){
v=laststep; minstep++;
cout<<minstep<<endl;
while(path[v]!=-){
s.push(v);
v=path[v];
}
while(!s.empty()){
v=s.top();
cout<<gra->G[v].x<<" "<<gra->G[v].y<<endl;
s.pop();
}
}else
cout<<<<endl;
}
int main(){
Graph gra=BuildGraph();
save(gra);
return ;
}
 

Saving James Bond - Hard Version的更多相关文章

  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. Saving James Bond - Easy Version (MOOC)

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

  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. pat05-图2. Saving James Bond - Easy Version (25)

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

  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. PAT Saving James Bond - Easy Version

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

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

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

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

随机推荐

  1. _bzoj1257 [CQOI2007]余数之和sum【小技巧】

    传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1257 最近刚做了一道莫比乌斯的题,需要用到这种方法. 应该让k / i相等的一连串k % i ...

  2. Mysql查询语句的 where子句、group by子句、having子句、order by子句、limit子句

    Mysql的各个查询语句 一.where子句   语法:select *|字段列表 from 表名 where 表达式.where子句后面往往配合MySQL运算符一起使用(做条件判断) 作用:通过限定 ...

  3. Win10 Hyper-v 中安装 CentOS 搭建开发环境

    Windows 环境 操作系统:Windows 10 开发环境:VS2005(需启动.NET Framework 3.5 ,才能正常安装使用)  Linux 环境 发行版:CentOS 7_x64 安 ...

  4. 525 Contiguous Array 连续数组

    给定一个二进制数组, 找到含有相同数量的 0 和 1 的最长连续子数组.示例 1:输入: [0,1]输出: 2说明: [0, 1] 是具有相同数量0和1的最长连续子数组. 示例 2:输入: [0,1, ...

  5. P1615 西游记公司

    题目背景 一道极其无厘头的题目 题目描述 事情是这样的:西游记中的孙沙猪(孙杀猪)三徒弟在西天取经之后开始进入厦门大学经贸系学习经济,在1个小时的学习后,他们用暴力手段毕业了.然后,他们创办了三个公司 ...

  6. python的与或非运算

    真的很重要,栽了个跟头!!!(虽然以前好像知道...) print(True or False and False) print((True or False) and False) # True # ...

  7. Scrapy-Redis分布式爬虫小白问题记录

    1.首先我是将Redis装在了阿里云的一台CentOS6.8上,使用ps -ef|grep redis查看是否成功运行 2.CentOS安装scrapy请参考 http://blog.csdn.net ...

  8. 洛谷 P1803 凌乱的yyy

    题目背景 快noip了,yyy很紧张! 题目描述 现在各大oj上有n个比赛,每个比赛的开始.结束的时间点是知道的. yyy认为,参加越多的比赛,noip就能考的越好(假的) 所以,他想知道他最多能参加 ...

  9. bitcoin 源码解析 - 交易 Transaction

    bitcoin 源码解析 - 交易 Transaction(三) - Script 之前的章节已经比较粗略的解释了在Transaction体系当中的整体运作原理.接下来的章节会对这个体系进行分解,比较 ...

  10. mysql踩坑记录之limit和sum函数混合使用问题

    问题复盘本次复盘会用一个很简单的订单表作为示例. 数据准备订单表建表语句如下(这里偷懒了,使用了自增ID,实际开发中不建议使用自增ID作为订单ID) CREATE TABLE `order` ( `i ...