#include<stdio.h>
#include<string.h>
#include<math.h>
#define inf 0x3fffffff
#define N 200
#define eps 1e-10
#include<queue>
using namespace std;
struct node {
int x,y;
}ma[N];
struct nodee {
int u,v,next;
double w;
}bian[N*N];
int yong,head[N],n;
void addedge(int u,int v,double w) {
bian[yong].u=u;
bian[yong].v=v;
bian[yong].w=w;
bian[yong].next=head[u];
head[u]=yong++;
}
double MIN(double a,double b) {
return a>b?b:a;
}
void bfs() {//宽搜
queue<int>q;
double dist[N];
int step[N],i,visit[N];
memset(visit,0,sizeof(visit));
while(!q.empty())
q.pop();
q.push(0);
for(i=1;i<=n+1;i++)
dist[i]=inf;
step[0]=0;
dist[0]=0;visit[0]=1;
while(!q.empty()){
int cur=q.front();
q.pop();
for(i=head[cur];i!=-1;i=bian[i].next) {
int v=bian[i].v;
if((dist[v]>dist[cur]+bian[i].w+eps||fabs(dist[v]-dist[cur]-bian[i].w)<=eps)&&step[v]>step[cur]+1&&visit[v]==0) {//判断条件如果相等就要比较它的最少的步数
step[v]=step[cur]+1;
dist[v]=dist[cur]+bian[i].w;
visit[v]=1;
q.push(v);
}
}
}
if(dist[n+1]<inf)
printf("%.2f %d\n",dist[n+1],step[n+1]);
else
printf("can't be saved\n");
return ;
}
int main() {
int i,j,s,t;
double limit,minn;
while(scanf("%d%lf",&n,&limit)!=EOF) {
t=n+1;s=0;
yong=0;
memset(head,-1,sizeof(head));
for(i=1;i<=n;i++) {
scanf("%d%d",&ma[i].x,&ma[i].y);
minn=MIN(fabs(50.0-fabs(1.0*ma[i].x)),fabs(50.0-fabs(1.0*ma[i].y)));
if(minn<limit+eps) {//将符合条件的边
addedge(i,t,minn);
addedge(t,i,0);//
}
minn=fabs(sqrt(1.0*ma[i].x*ma[i].x+1.0*ma[i].y*ma[i].y)-7.5);
if(minn<limit+eps) {
addedge(s,i,minn);//
addedge(i,s,0);//
}
}
if(limit+eps>42.50) {//如果可以直接跳到岸上就直接输出
printf("42.50 1\n");
continue;
}
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++) {
minn=inf;
minn=MIN(minn,sqrt(1.0*(ma[i].x-ma[j].x)*(ma[i].x-ma[j].x)+1.0*(ma[i].y-ma[j].y)*(ma[i].y-ma[j].y)));
if(minn<limit+eps) {
addedge(i,j,minn);
addedge(j,i,minn);//双向边
}
}
bfs();
}
return 0;
}

hdu 1245 Saving James Bond 策画几何+最短路 最短路求步数最少的路径的更多相关文章

  1. hdu 1245 Saving James Bond

    http://acm.hdu.edu.cn/showproblem.php?pid=1245 #include <cstdio> #include <cstring> #inc ...

  2. Saving James Bond(dijk)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1245 Saving James Bond Time Limit: 6000/3000 MS (Java ...

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

  4. Saving James Bond - Easy Version (MOOC)

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

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

    06-图4. Saving James Bond - Hard Version (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...

  6. pat05-图2. Saving James Bond - Easy Version (25)

    05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...

  7. Saving James Bond - Hard Version

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

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

  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. jQuery - 制作非缘勿扰页面特效

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. Android之——常见Bug及其解决方式

    转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46942139 1.android.view.WindowManager$BadTo ...

  3. android recovery 系统代码分析 -- 选择进入【转】

    本文转载自:http://blog.csdn.net/andyhuabing/article/details/9226569 最近做Recovery的规范及操作指导文档,花了一些时间将流程搞清. An ...

  4. write data to xml

    public class Student { public int Id { get; set; } public string FirstName { get; set; } public stri ...

  5. Codeforces--615B--Longtail Hedgehog(贪心模拟)

     B. Longtail Hedgehog time limit per test 3 seconds memory limit per test 256 megabytes input stan ...

  6. iOS沙盒及数据存储

    时间久了容易忘,针对沙盒的相关实用技巧做一个记录和整理. 一.iOS数据存储常用方式 1.XML属性列表(plist) 不是所有对象都可以写入: 2.Preference(偏好设置) 本质还是通过“p ...

  7. 88. [ExtJS2.1教程-5]ToolBar(工具栏)

    转自:https://llying.iteye.com/blog/324681 面板中可以有工具栏,工具栏可以位于面板顶部或底部,Ext中工具栏是由Ext.Toolbar类来表示.工具栏上可以放按钮. ...

  8. AOP实现参数的判空问题

    不想每次都去判断必传的参数是否为空,写代码太繁琐了,正好最近用了AOP实现权限控制,依葫芦画瓢,现在用它实现参数的判空,至于AOP的原理之类,自己百度了解一下吧 1. NullDisable注解 @D ...

  9. Java调用JavaWebService

    1.pom配置 <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId&g ...

  10. sql 改字段名

    sp_rename '[zErpMini].[dbo].[STK_Stock].Isextension','IsExtened'