题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1245

Saving James Bond

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2608    Accepted Submission(s): 505

Problem Description
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×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 whether he could
escape.If he could,tell him the shortest length he has to jump and the
min-steps he has to jump for shortest length.
 
Input
The
input consists of several test cases. Each case starts with a line
containing n <= 100, the number of crocodiles, and d > 0, the
distance that James could jump. Then one line follows for each
crocodile, containing the (x, y) location of the crocodile. Note that x
and y are both integers, and no two crocodiles are staying at the same
position.
 
Output
For
each test case, if James can escape, output in one line the shortest
length he has to jump and the min-steps he has to jump for shortest
length. If it is impossible for James to escape that way, simply ouput
"can't be saved".
 
Sample Input
4 10
17 0
27 0
37 0
45 0
1 10
20 30
 
Sample Output
42.50 5
can't be saved
 
Author
weigang Lee
 
题意: 湖是以(0,0)为中心的边长为100的正方形,开始小人在湖中心直径为15的岛上,中间的湖有很多的鳄鱼,求小人可以通过鳄鱼跳到岸上吗,小人每次跳跃距离不超过d
题解: 这个题建图是关键,建好图,用dijk或者是spfa求最短路都可以,将中心岛看成第一个点,将岸边看成是第n+2个点,然后枚举所有的两点之间,如果之间距离小于d就建一条两点之间的边,
再枚举每个点和中心岛屿和岸边的距离和岛屿和岸边建边,然后求最短路即可
复习一下dijk
代码:
 #include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
#define INF 0x1fffffff
#define N 110
struct Edge{
int to;
int next;
double v;
}edge[N*N]; struct point{
double x;
double y;
}p[N]; int head[N];
int m;
double fd(double x1, double y1, double x2 , double y2)
{
double tm = (x2-x1)*(x2-x1) +(y2-y1)*(y2-y1);
return sqrt(tm);
}
double dis[N];
int cnt[N];
int Enct;
bool vis[N];
void init()
{
Enct = ;
memset(head,-,sizeof(head));
memset(vis, , sizeof(vis));
for(int i = ;i < N ; i++){
dis[i] = INF;
cnt[i] = INF;
}
cnt[] = ;
dis[] = ;
}
void add(int from , int to , double v)
{
if(v>m) return ;
edge[Enct].to = to;
edge[Enct].v = v;
edge[Enct].next = head[from];
head[from] = Enct++;
edge[Enct].to = from;
edge[Enct].v = v;
edge[Enct].next = head[to];
head[to] = Enct++;
}
int n; void dijk()
{
for(int i = ;i < n ;i++)
{
//for(int j = 0; j < n; j++) printf("%.2lf ", dis[j]); puts("");
int Min = INF ;
int Minc = INF ;
int k = -;
for(int j = ; j < n ; j++)
{
if(!vis[j]&&dis[j]<=Min)
{
if(dis[j]<Min)
{
Min = dis[j];
k = j;
}
else if(dis[j]==Min&&cnt[j]<Minc)
{
Minc = cnt[j];
k = j;
}
}
}
//printf("%d \n",k);
if(Min == INF) return ;
vis[k] = ;
for( int j = head[k] ; j != - ; j = edge[j].next)
{
Edge e = edge[j];
if(!vis[e.to]&&(dis[k]+e.v)==dis[e.to]&&cnt[k]+<cnt[e.to])
{
cnt[e.to] = cnt[k]+;
}
if(!vis[e.to]&&dis[k]+e.v<dis[e.to])
{
cnt[e.to] = cnt[k]+;
dis[e.to] = dis[k]+e.v;
}
}
}
} int main()
{
while(~scanf("%d%d",&n,&m))
{
init();
for(int i = ; i <= n ;i++)
{
double x, y;
scanf("%lf%lf",&x,&y);
p[i].x = x;
p[i].y = y;
double dd = -max(fabs(x), fabs(y));
if(dd <= m) add(i, n+, dd);
//if((x>=50-m&&x>y)||(x<=-(50-m)&&x<y)) add(i,n+1,(50-abs(x)));
//if((y>=50-m&&x<y)||(y<=-(50-m)&&x>y)) add(i,n+1,(50-abs(y)));
for(int j = ; j < i ; j++)
{
double flag = fd(p[i].x,p[i].y,p[j].x,p[j].y);
if(flag <= m) add(i,j,flag);
}
}
for(int i = ; i <= n; i++)
{
double tm = fd(p[i].x, p[i].y, , );
if(tm - 7.5 <= m) add(, i, tm - 7.5);
}
// for(int i = 0; i < n+2; i++)
// {
// printf("%d:", i);
//for(int j = head[i]; j != -1; j = edge[j].next) printf("(%d %.2lf) ", edge[j].to, edge[j].v);
// puts("");
// } n += ;
dijk();
if(dis[n-]==INF) puts("can't be saved");
else
printf("%.2f %d\n",dis[n-],cnt[n-]-);
}
return ;
}

Saving James Bond(dijk)的更多相关文章

  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 - 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. bzoj 1855: [Scoi2010]股票交易

    Description 最近lxhgww又迷上了投资股票,通过一段时间的观察和学习,他总结出了股票行情的一些规律. 通过一段时间的观察,lxhgww预测到了未来T天内某只股票的走势,第i天的股票买入价 ...

  2. Nginx学习之配置RTMP模块搭建推流服务

    写在开始 小程序升级实时音视频录制及播放能力,开放 Wi-Fi.NFC(HCE) 等硬件连接功能.同时提供按需加载.自定义组件和更多访问层级等新特性,增强了第三方平台的能力,以满足日趋丰富的业务需求. ...

  3. 麻瓜之我要学sql,啦啦啦啦

    四张表 学生表:编号,姓名,性别,班级,生日 CREATE TABLE IF NOT EXISTS student( sno TINYINT UNSIGNED NOT NULL, sname ) NO ...

  4. DBA之路

    对于一个励志要成为DBA的人,虽然还有不足,梦想还是要有的,万一实现了呢.做一个关于DBA成长之路的相关目录,作为灯塔. --------------------------------------- ...

  5. JavaScript的DOM编程--07--节点的属性

    节点的属性: 1). nodeName: 代表当前节点的名字. 只读属性. 如果给定节点是一个文本节点, nodeName 属性将返回内容为 #text 的字符串 2). nodeType:返回一个整 ...

  6. 大数据学习系列之八----- Hadoop、Spark、HBase、Hive搭建环境遇到的错误以及解决方法

    前言 在搭建大数据Hadoop相关的环境时候,遇到很多了很多错误.我是个喜欢做笔记的人,这些错误基本都记载,并且将解决办法也写上了.因此写成博客,希望能够帮助那些搭建大数据环境的人解决问题. 说明: ...

  7. css3弹性盒模型flex快速入门与上手(align-content与align-items)

    接着上文css3弹性盒模型flex快速入门与上手1继续,上文还剩下两个父容器的属性align-items和align-content. 一.align-content:多行的副轴对齐方式 含义 多行的 ...

  8. 通过window.location.search获取页面url传递的参数

    function GetQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...

  9. jdk8新特性(文章推荐)

    文章推荐 jdk9都已经出来了,虽然很多项目都已经使用jdk8,但是很少会用到jdk8中的新特性.本人经常用的到也就是使用Stream,Lambda,但也仅仅是使用,基本不知道什么Function,C ...

  10. [笔记]《JavaScript高级程序设计》- 最佳实践

    一.可维护性 1 什么是可维护的代码 可理解性--其他人可以接受代码并理解它的意图和一般途径,而无需原开发人员的完整解释. 直观性--代码中的东西一看就能明白,不管其操作过程多么复杂. 可适应性--代 ...