hdu 1245 Saving James Bond 策画几何+最短路 最短路求步数最少的路径
#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 策画几何+最短路 最短路求步数最少的路径的更多相关文章
- hdu 1245 Saving James Bond
http://acm.hdu.edu.cn/showproblem.php?pid=1245 #include <cstdio> #include <cstring> #inc ...
- Saving James Bond(dijk)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1245 Saving James Bond Time Limit: 6000/3000 MS (Java ...
- 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 ...
- Saving James Bond - Easy Version (MOOC)
06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...
- pat06-图4. Saving James Bond - Hard Version (30)
06-图4. Saving James Bond - Hard Version (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...
- pat05-图2. Saving James Bond - Easy Version (25)
05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...
- Saving James Bond - Hard Version
07-图5 Saving James Bond - Hard Version(30 分) This time let us consider the situation in the movie &q ...
- 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 ...
- PAT Saving James Bond - Easy Version
Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...
随机推荐
- 【c语言】字符串替换空格:请实现一个函数,把字符串中的每一个空格替换成“%20”
// 字符串替换空格:请实现一个函数,把字符串中的每一个空格替换成"%20". // 比如输入"we are happy.",则输出"we%20are ...
- Coursera Algorithms week2 基础排序 练习测验: Intersection of two sets
题目原文: Given two arrays a[] and b[], each containing n distinct 2D points in the plane, design a subq ...
- (Go)07.Go语言中strings和strconv包示例代码详解02
1.strings使用 统计字符串出现次数 strings.Count(s string, substr string) int Count 用于计算字符串 substr 在字符串 s 中出现的非重叠 ...
- PCB 全景图技术实现
为了对3D模型理解更透,这里采用threejs(WebGL第三方库)实现,刚开始学习入门,为了能看明白基本上每行代码都注释. 如果仅仅是为了实现全景图,可以用photo-sphere-viewer.j ...
- 0423-mysql插入语句大全
/*注意: 1.字段和值要一一对应 2.值的数据类型是字段的数据类型 3.当输入的字段是表中全部字段时,字段可以省略不写: insert into login values ('zhangsan',‘ ...
- php处理类
Thomas Boutell 以及众多的开发者创造了以GD图形库闻名的一个图形软件库,用于动态的图形计算. GD提供了对于诸如C, Perl, Python, PHP, OCaml等等诸多编程语言的支 ...
- [Apple开发者帐户帮助]二、管理你的团队(5)转移帐户持有人角色
组织团队的帐户持有人可以将帐户持有人角色转移给团队中的其他人.如果您是个人注册并需要将您的会员资格转移给其他人,请与我们联系. 所需角色:帐户持有人. 转移Apple Developer Progra ...
- netty支持SSL,OpenSSL
import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; import io.netty.handler ...
- B - Taxi(贪心)
Problem description After the lessons n groups of schoolchildren went outside and decided to visit P ...
- jquery.validate验证text,checkbox,radio,selected
index.cshtml <form id="formLogin" method="post"> <div> <label for ...