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. 看图了解RocksDB

    它是一个高性能的Key-Value数据库.设计了完善的持久化机制,同时保证性能和安全性.能够良好的支持范围查询,因为K-V记录就是按照Key来排序的. 下图为写入的流程: ​ 可以看到主要的三个组成部 ...

  2. 浅析弹性公网IP付费模式和短时升配功能介绍

    ​ 弹性公网IP付费模式对比 弹性公网IP(EIP),有两种付费方式.一种是预付费,一种是后付费.对于预付费弹性公网IP而言,最大的优点就是带宽费用便宜,相对于后付费有比较大的优惠. 例如,杭州地域6 ...

  3. 三、PCB设计与Allegro基本概念

    PCB:印制电路板 如--update更新时无法变为0 4.区域规则--设置区域规则--赋予区域轮廓 5.铜皮 把.sav改为.dsn--就可以恢复出突然关闭的.dsn文件 生成规则钻孔文件(.drl ...

  4. git merge 上线操作流程

    switch to branch git merge 主干到分支解决冲突,解决冲突文件,冲突文件,add to index 检查文件无<<<<<<< .=== ...

  5. NAGIOS(网络监视工具)

    Nagios是一款开源的免费网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机,路由器等网络设备,打印机等.在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员 ...

  6. window安装nodejs

    nvm管理nodejs 原文: https://www.cnblogs.com/shimily/articles/7244058.html1.下载nvm(nodejs版本管理工具) https://g ...

  7. [codeforces 508E]Maximum Matching

    题目:Maximum Matching 传送门:http://codeforces.com/contest/1038/problem/E 分析: 一个块拥有{color1,val,color2},两个 ...

  8. [CSP-S模拟测试]:山洞(DP+快速幂)

    题目传送门(内部题17) 输入格式 一行两个整数$n$,$m$,含义如题面. 输出格式 一行一个整数,表示方案数模$1e9+7$. 样例 样例输入1: 4 6 样例输出1: 样例输入2: 707 18 ...

  9. 使用juqery-ui完成联想查询功能

    最近公司的项目有个需求,需要使用联想查询功能.就是一个文本输入框,在输入的时候获取值去后端模糊查询然后按照列表显示在下面.效果如下图: 经过搜索找到这个插件,查阅资料可以完成这个功能,即可以实现静态数 ...

  10. 2018-2019 2 20165203 《网络对抗技术》Exp8 Web基础

    2018-2019 2 20165203 <网络对抗技术>Exp8 Web基础 实验要求 1.本实践的具体要求有: (1) Web前端HTML(0.5分) 能正常安装.启停Apache.理 ...