hdu 1245 Saving James Bond
http://acm.hdu.edu.cn/showproblem.php?pid=1245
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#define maxn 500
using namespace std;
const double inf=99999999.0; int n,m;
double d;
double g[maxn][maxn];
double dis[maxn];
bool vis[maxn];
int step[maxn*];
struct node
{
int x,y;
}p[maxn]; double min(double x,double y)
{
if(x>y) return y;
return x;
} double sqr(int x)
{
return x*x;
} double dist(int x1,int y1,int x2,int y2)
{
return sqrt(sqr(x1-x2)+sqr(y1-y2));
} void spfa()
{
queue<int>q;
memset(vis,false,sizeof(vis));
for(int i=; i<=n+; i++)
{
dis[i]=inf;
}
dis[]=0.0;
vis[]=true;
step[]=;
q.push();
while(!q.empty())
{
int u=q.front(); q.pop();
vis[u]=false;
for(int i=; i<=n+; i++)
{
if(g[u][i]<=d)
{
if(g[u][i]+dis[u]<dis[i])
{
dis[i]=dis[u]+g[u][i];
step[i]=step[u]+;
if(!vis[i])
{
vis[i]=true;
q.push(i);
}
}
else if(g[u][i]+dis[u]==dis[i])
{
if(step[i]>step[u]+)
{
step[i]=step[u]+;
if(!vis[i])
{
vis[i]=true;
q.push(i);
}
}
}
}
}
}
}
int main()
{
while(scanf("%d%lf",&n,&d)!=EOF)
{
for(int i=; i<=n; i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
}
for(int i=; i<=n; i++)
{
g[i][i]=0.0;
for(int j=; j<=n; j++)
{
g[i][j]=dist(p[i].x,p[i].y,p[j].x,p[j].y);
}
}
g[][]=0.0;
for(int i=; i<=n; i++)
{
g[i][]=0.0;
g[][i]=dist(,,p[i].x,p[i].y)-7.5;
}
for(int i=; i<=n; i++)
{
g[n+][i]=0.0;
g[i][n+]=min(50.0-fabs((double)p[i].x),50.0-fabs((double)p[i].y));
}
g[][n+]=inf;
spfa();
if(dis[n+]==inf)
printf("can't be saved\n");
else
printf("%.2lf %d\n",dis[n+],step[n+]);
}
return ;
}
hdu 1245 Saving James Bond的更多相关文章
- hdu 1245 Saving James Bond 策画几何+最短路 最短路求步数最少的路径
#include<stdio.h> #include<string.h> #include<math.h> #define inf 0x3fffffff #defi ...
- 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 ...
随机推荐
- hdu 1385 Minimum Transport Cost
http://acm.hdu.edu.cn/showproblem.php?pid=1385 #include <cstdio> #include <cstring> #inc ...
- JavaScript中String对象处理HTML标记中文本的方法
big():创建一个<big></big>标记,将这个字符串的字体变大blink():创建一个<blink></blink>标记,使字符串具有闪烁效果b ...
- 关于NSIS脚本的Demo
这个NSIS脚本是打包公司的整个Release项目工程. 用NSIS编译器编译下就可以了. ; Script generated by the HM NIS Edit Script Wizard. ! ...
- Some General concepts in ISO C
[ISO C11 Clause 3]对象(object):执行环境中数据存储的一块区域,它的内容可以用来表示值.-注释:对象可以具有特定的类型.--值(value):确定类型的对象的内容的确切含义.- ...
- cf437B The Child and Set
B. The Child and Set time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Manacher算法----最长回文子串
题目描述 给定一个字符串,求它的最长回文子串的长度. 分析与解法 最容易想到的办法是枚举所有的子串,分别判断其是否为回文.这个思路初看起来是正确的,但却做了很多无用功,如果一个长的子串包含另一个短一些 ...
- lucene 高亮显示
原文地址: http://blog.csdn.net/javaman_chen/article/details/8224407 Lucene针对高亮显示功能提供了两种实现方式,分别是Highlight ...
- Query语句对系统性能的影响
需求: 取出某个group(假设id为1)下的用户编号id,用户昵称(nick_name),并按照加入组的时间(user_group.gmt_create)来进行倒序排列,取出前20个 解决方案一: ...
- 5狐网教你从零基础做Firefox os 手机应用开发赚money
如果你还没有接触过web编程,这里有基础教程教你怎样一步一步学习开发,如果你已经是一个web编程基础的人,那你就很容易将web编程放到手机上,轻松教你移植web应用游戏到Firefox手机应用再发布到 ...
- Python进阶之路---1.4python数据类型-数字
python入门基础 声明:以后python代码未注明情况下,默认使用python3.x版本 1.python代码基础:print print('hello,python') 1.1pyt ...