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. C#条码生成及打印实例代码

    ";//条码 ; ; //打印按钮 private void button1_Click(object sender, EventArgs e) { //实例化打印对象 PrintDocum ...

  2. JavaScript入门(二)

    JavaScript入门—操作DOM树 要点 DOM树是一个树形结构,操作DOM树通常是“更新.遍历.新增.删除”. 更新DOM树 拿到DOM节点 var id=document.getElement ...

  3. C# vb .NET读取识别条形码线性条码code39

    code39是比较常见的条形码编码规则类型的一种.如何在C#,vb等.NET平台语言里实现快速准确读取该类型条形码呢?答案是使用SharpBarcode! SharpBarcode是C#快速高效.准确 ...

  4. StarGAN学习笔记

    11 December 2019 20:32 来自 <https://zhuanlan.zhihu.com/p/44563641>     StarGAN StarGAN是CVPR2018 ...

  5. Java操作JSON数据(4,end)--Jackson操作JSON数据

    Jackson是SpringBoot默认使用的JSON处理库,它可以轻松的将Java对象转换成JSON对象,同样也可以将JSON转换成Java对象.本文介绍下Jackson的基本使用方法,包括序列化和 ...

  6. 基于python的图像傅里叶处理

    import numpy as npimport matplotlib.pyplot as plt x = np.linspace(-10, 10, 1000)a = np.cos(x)b = a + ...

  7. python爬虫---scrapy框架爬取图片,scrapy手动发送请求,发送post请求,提升爬取效率,请求传参(meta),五大核心组件,中间件

    # settings 配置 UA USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, l ...

  8. SSM之Mybatis整合及使用

    SSM 在ss基础上加进行整合Mybatis(applicationContext.xml中添加配置),并添加分页拦截器(添加mybatis分页拦截器),并用generator动态生成到层. 构建基础 ...

  9. Vue学习之路由vue-router小结(九)

    一.路由: 1.后端路由: 对于普通网站,所有的超链接都是URL地址,所有的URL地址都对应服务器上对应的资源: 2.前端路由: 对于单页面应用程序来说,主要通过URL中的hash(#号)来实现不同页 ...

  10. javascript:void(0)的含义

    void关键字介绍 首先,void关键字是javascript当中非常重要的关键字,该操作符指定要计算或运行一个表达式,但是不返回值. 语法格式: void func() void(func()) 实 ...