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 ...
随机推荐
- Android Back键和Home键的区别
back键 Android的程序无需刻意的去退出,当你一按下手机的back键的时候,系统会默认调用程序栈中最上层Activity的Destroy()方法来,销毁当前Activity.当此Activit ...
- poj--2031--Building a Space Station(prime)
Building a Space Station Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6635 Accepte ...
- expectation-maximization algorithm ---- PRML读书笔记
An elegant and powerful method for finding maximum likelihood solutions for models with latent varia ...
- 92. extjs specialkey监听回车按键
转自:http://blog.sina.com.cn/s/blog_647a022e0101401n.html 1 监听表单字段事件: Ext使得对用户某个动作的监听特别简单,诸如单击某个元素或者按下 ...
- 83.个人信息维护页面 Extjs 页面
1 <%@ page language="java" import="java.util.*" pageEncoding="UTF-8" ...
- 跟渣渣辉玩ffms
[SQL] /* Navicat MySQL Data Transfer Source Server : root Source Server Version : 50717 Source Host ...
- CAS配置(1)SSL证书配置
一.配置源码 源码配置稍后提供 二.系统环境安装 安装JDK配置,版本>=1.7 环境变量配置(参考): JAVA_HOME=C:\Program Files x86)\Java\jdk1.7. ...
- B - Sleuth
Problem description Vasya plays the sleuth with his friends. The rules of the game are as follows: t ...
- B - Eleven
Problem description Eleven wants to choose a new name for herself. As a bunch of geeks, her friends ...
- 跳出双重for循环的案例__________跳出了,则不再执行标签ok下的for循环代码
ok: for (int i = 0; i < 3; i++) { for (int j = 0; j < 4; j++) { System.out.print("*" ...