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
我的答案(最大N没过)
 #include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h> #define QMAXSIZE 10000 struct Crocodile {
int x;
int y;
int Visited;
int Path;
};
typedef struct Crocodile *Point; //队列部分
struct QNode {
int Data[QMAXSIZE];
int rear;
int front;
};
typedef struct QNode *Queue; int IsEmpty(Queue Q)
{
return (Q->rear == Q->front);
} void AddQ(Queue PtrQ, int item)
{
if((PtrQ->rear+)%QMAXSIZE == PtrQ->front) {
printf("Queue full");
return;
}
PtrQ->rear = (PtrQ->rear+)%QMAXSIZE;
PtrQ->Data[PtrQ->rear] = item;
} int DeleteQ(Queue PtrQ)
{
if(PtrQ->front == PtrQ->rear) {
printf("Queue empty");
return -;
} else {
PtrQ->front = (PtrQ->front+)%QMAXSIZE;
return PtrQ->Data[PtrQ->front];
}
} void PrintQ(Queue PtrQ)
{
int i;
printf("[Queue]: ");
for(i=(PtrQ->front+)%QMAXSIZE;i!=(PtrQ->rear+)%QMAXSIZE
;i=(i+)%QMAXSIZE)
printf("%d ", PtrQ->Data[i]);
printf("\n");
}//end Queue void ReadPoint(Point P, int N)
{
int i;
P[].x = ;
P[].y = ;
P[].Visited = ;
P[].Path = -;
for(i=;i<N;i++) { //N=N+1
scanf("%d %d\n", &P[i].x, &P[i].y);
P[i].Visited = ;
}
} void PrintfPoint(Point P, int N)
{
int i;
for(i=;i<N;i++) { //N=N+1
printf("P[%d] X:%d Y:%d\n", i, P[i].x, P[i].y);
}
printf("----------------------------\n");
} void PrintPath(Point P, int stand)
{
int Path[], i;
// printf("[PrintPath] stand=%d\n", stand);
// if(P[stand].Path != -1) {
// PrintPath(P, P[stand].Path);
// printf("%d %d\n", P[stand].x, P[stand].y);
// }
if(stand==) printf("1\n");
else {
for(i=;P[stand].Path != -;i++) {
Path[i] = stand;
stand = P[stand].Path;
}
// printf("[PrintPaht] i=%d\n", i);
printf("%d\n", i+);
for(i--;i>=;i--) {
printf("%d %d\n", P[Path[i]].x, P[Path[i]].y);
}
}
} double PointDistance(Point P1, Point P2)
{
return sqrt(pow((P1->x - P2->x), ) + pow((P1->y - P2->y), ));
} double FindMinPath(Point P, int stand)
{
while(P[stand].Path != ) {
stand = P[stand].Path;
}
return PointDistance(&P[], &P[stand]);
} int IsUp(Point P, int stand, double D, int island)
{
int xlen = -abs(P[stand].x);
int ylen = -abs(P[stand].y);
if(island == && (xlen<=(D+7.5) || ylen<=(D+7.5)))
return ;
else if(stand!= && (xlen<=D || ylen <=D))
return ;
return ;
} int IsUseless(Point P, int stand)
{
if(abs(P[stand].x) <= 7.5 && abs(P[stand].y) <= 7.5 )
return ;
else if(abs(P[stand].x == && abs(P[stand].y == )))
return ;
else
return ;
} void Visit(Point P, int stand)
{
printf("[Point] P.x:%d y:%d\n", P[stand].x, P[stand].y);
} int BFS(Point P, int N, double D, int stand)
{
Queue Q;
int S, i, endP=-;
double dist, island = , minDist=; Q = (Queue)malloc(sizeof(struct QNode)*N);
// Visit(P, stand); //访问P[0]
P[stand].Visited = ;
AddQ(Q, stand); while(!IsEmpty(Q)) {
// PrintQ(Q);
S = DeleteQ(Q); //提取队列
if(S == ) //是否在岛上
island = ;
else
island = ;
if(IsUp(P, S, D, island)) {
endP = S;
break;
} for(i=;i<N;i++) {
if(IsUseless(P, i)) continue;
dist = PointDistance(&P[S], &P[i]);
if(!P[i].Visited && dist<=(D+(double)island*7.5)) { //未被访问且能跳到
// Visit(P, i);
P[i].Path = S;
if(IsUp(P, i, D, island)) {
// printf("[Ok] Here Point can go up\n");
// printf("[Path] \n");
// PrintPath(P, i);
// printf("\n");
double temp;
temp = FindMinPath(P, i);
if(minDist > temp) {
minDist = temp;
endP = i;
}
}
P[i].Visited = ;
AddQ(Q, i);
// dist = D+1;
}
}
}
return endP;
} int main()
{
int N, endP;
double D;
Point P;
scanf("%d %lf", &N, &D);
N++; //从1开始
P = (Point)malloc(sizeof(struct Crocodile)*N);
ReadPoint(P, N);
// PrintfPoint(P, N); endP = BFS(P, N, D, );
// printf("minP:%d\n", endP);
if(endP == -)
printf("0\n");
else {
PrintPath(P, endP);
}
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. Linux服务的安装与使用

    Spotlight on Unix 监控Linux服务器的安装与使用 详细请看:https://spotlight-on-unix.software.informer.com/download/#do ...

  2. 英语单词retrieve

    retrieve 来源——报错信息 [root@centos65 ~]# yum whatprovides */lsb_release Loaded plugins: fastestmirror, s ...

  3. 项目中有 xxxx 不能被json序列化

    遇到这类问题 ,首先断点调试,看看要序列化的值 是一个什么类型的值 查看值得数据类型 在将值转化成可以被json序列化的对象 此时即可解决问题 如遇到  requests.post() 朝一个url发 ...

  4. Code Review怎样做好

    一.背景 最近随着交易业务快速扩展,研发组内新项目及新成员越来越多,如何做好Code Review,把控研发人员开发代码质量很是关键. 对于大部分业务团队,谈到Code Review就会面露哀状:   ...

  5. 在Android中实现一个简易的Http服务器

    最近遇到一个需求需要在App中创建一个Http服务器供供浏览器调用,用了下开源的微型Htpp服务器框架:NanoHttpd,项目地址:https://github.com/NanoHttpd/nano ...

  6. 安装并配置前端自动化工具-gulp

    由于现在前端自动化已经很有必要了,所以我今天死皮烂脸的找了2位前端大咖帮助我安装和配置gulp,讲真,这一步步弄下来直到安装配置成功,到现在还是迷迷糊糊,不过我还是把这些步骤给记录下来,以防下次不记得 ...

  7. 51nod 1518 稳定多米诺覆盖(容斥+二项式反演+状压dp)

    [传送门[(http://www.51nod.com/Challenge/Problem.html#!#problemId=1518) 解题思路 直接算不好算,考虑容斥,但并不能把行和列一起加进去容斥 ...

  8. qbxt Day2 on 19-7-25

    qbxt Day2 on 19-7-25 --TGZCBY 上午 1. 矩阵乘法在图论上的应用 有的时候图论的转移方程可以用dp的方式转移 特别是两个数的乘积求和的时候 比如邻接矩阵中f[i][j]表 ...

  9. JQuery判断radio(单选框)是否选中和获取选中值

    一.设置选中方法 代码如下: $("input[name='名字']").get(0).checked=true; $("input[name='名字']"). ...

  10. ecs centos7.3 搭建vsftpd 虚拟用户

    FTP介绍 FTP会话时包含了两个通道,一个叫控制通道,端口号21:一个叫数据通道,端口号20. 控制通道:控制通道是和FTP服务器进行沟通的通道,连接FTP,发送FTP指令都是通过控制通道来完成的. ...