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

时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue

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)的更多相关文章

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

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

  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 - Hard Version

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

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

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

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

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

随机推荐

  1. 关于CRTP(Curiously Recurring Template Prattern)的使用

    在阅读frameworks/rs/cpp/util/RefBase.h之LightRefBase时,我记得<C++设计新思维>里对这种用法是有过介绍的,可是今天翻箱倒柜,怎么都找不到那本奇 ...

  2. 【bzoj1853】: [Scoi2010]幸运数字 数论-容斥原理

    [bzoj1853]: [Scoi2010]幸运数字 预处理出所有幸运数字然后容斥原理 但是幸运数字是2logn个数的 直接搞会炸 所以把成倍数的处理掉 然后发现还是会T 所以数字要从大到小处理会快很 ...

  3. 【微框架】之一:从零开始,轻松搞定SpringCloud微服务系列--开山篇(spring boot 小demo)

    Spring顶级框架有众多,那么接下的篇幅,我将重点讲解SpringCloud微框架的实现 Spring 顶级项目,包含众多,我们重点学习一下,SpringCloud项目以及SpringBoot项目 ...

  4. P1505 [国家集训队]旅游

    \(\color{#0066ff}{题 目 描 述}\) Ray 乐忠于旅游,这次他来到了T 城.T 城是一个水上城市,一共有 N 个景点,有些景点之间会用一座桥连接.为了方便游客到达每个景点但又为了 ...

  5. 10.18 NOIP2018提高组模拟题(二)

    大水题 1.咒语 (curse.pas/c/cpp) [题目描述] 亮亮梦到自己来到了魔法城堡,但一扇巨大的石门阻拦了他通向城堡内的路.正当他沮丧之际,突然发现门上有一处机关,机关上有一张很长的纸条. ...

  6. SpriteBuilder 不能 Portrait

    最近用最新的SpriteBuilder V1.3.6和Xcode 6.0.1,发现一个bug.就是在使用Xcode6的时候的SpriteBuilder已经在Project settings 里面设置了 ...

  7. PXE刷机,存储节点失败

    最近刚刚帮客户对一台满配的X6-2刷机初始化,尝试了下PXE方式,但刷完机后,发现计算节点的imagehistory输出的状态都是成功的,而所有的存储节点状态都为failure,具体如下: [root ...

  8. python解释器安装

    1. 下载安装包 1   2 https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi    # 2.7安装包   https: ...

  9. APP设计规范

    设计师DPI指南 本指南旨在为初级到中级设计人员提供“入门”或介绍性阅读,他们希望从一开始就学习或获得有关跨DPI和跨平台设计的更多知识. 尽可能少的数学和没有不可解析的图形,只需在简短的部分中订购直 ...

  10. 利用DSB2017冠军开源代码为LUNA16生成mask

    代码地址:https://github.com/lfz/DSB2017 先展示下生成的mask与真实mask subset9 subset8 subset7 subset6 subset5 subse ...