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 ...
随机推荐
- 好记性不如烂笔头——WebService与Remoting
一.WebService总体上分为5个层次: 1)HTTP传输信道 2)XML的数据格式 3)SOAP的封装协议,用于传输 4)WSDL的描述方式,用于引用 5)UDDI,通用描述.发现与集成服务,用 ...
- Codeforces Round #276 (Div. 1)B. Maximum Value 筛法
D. Maximum Value You are given a sequence a consisting of n integers. Find the maximum possible ...
- 没有终结点在侦听可以接受消息的 http://192.168.1.63:8085/LoginService。这通常是由于不正确的地址或者 SOAP 操作导致的
2016-04-08 09:15:05,581 [8] ERROR System.Threading.Thread - ErrorSystem.ServiceModel.EndpointNotFoun ...
- 软件-版本控制:VCS(版本控制系统)
ylbtech-软件-版本控制:VCS(版本控制系统) 版本控制系统(Version Control System),是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.版本控制系统 ...
- 杂项:ESB接口
ylbtech-杂项:ESB接口 ESB全称为Enterprise Service Bus,即企业服务总线.它是传统中间件技术与XML.Web服务等技术结合的产物.ESB提供了网络中最基本的连接中枢, ...
- Gold Balanced Lineup(hash)
http://poj.org/problem?id=3274 ***** #include <stdio.h> #include <iostream> #include < ...
- Cuckoo for Hashing
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2719 #include <stdio.h ...
- codevs2596 售货员的难题(状压dp)
2596 售货员的难题 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 钻石 Diamond 题目描述 Description 某乡有n个村庄(1<n<=15 ...
- C#接入第三方支付一些小问题
13年第一次接入支付宝的时候,支付宝的api还不是很好用,费了些劲才完成,本月再次接入的时候发现已经很好用了,接入过程非常顺畅,只出现了一个小问题,我的金额默认是保留了4位小数,支付宝api只接受最多 ...
- Vue初级
来学习vue.js的宝宝们应该都了解了什么是vue并且是有兴趣去学的,我也是自己学习vue,欢迎大家一起讨论. 现在,我么先自己尝试用vue来写个hello world吧. 一.创建一个 .html ...