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 ...
随机推荐
- 使用Keil软件编写汇编源程序应注意事项
1)一定要使用微软的txt文本编辑器,否则键入逗号时编译通不过.应该是这个样('),不该是这个样(,). 2) 用数字做标号时,前面一定要加一个英文字母,否则编译通不过. 3) 有时编译通过的.asm ...
- 【转】android service 之二(IntentService)
原文网址:http://rainbow702.iteye.com/blog/1143286 不管是何种Service,它默认都是在应用程序的主线程(亦即UI线程)中运行的.所以,如果你的Service ...
- bzoj3174 [Tjoi2013]拯救小矮人
Description 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以碰到陷阱口.对于每一个小矮人, ...
- 关于背景透明,文字不透明的最佳方法,兼容IE
以背景黑色,透明度0.5举例 非IE:background:rgba(0,0,0,0.5); IE:filter:progid:DXImageTransform.Microsoft.gradient( ...
- HTML与CSS入门——第九章 使用颜色
知识点: 1.为网站选择颜色的方法 2.颜色在Web上的工作方式 3.使用十六进制颜色值的方法 4.使用CSS设置背景.文本和边框颜色的方法 9.1 选择颜色的最佳方法: 直白地说:根据用户群体找到最 ...
- 对arm指令集的疑惑,静态库运行,编译报错等问题
转载自http://www.jianshu.com/p/4a70aa03a4ea?utm_campaign=hugo&utm_medium=reader_share&utm_conte ...
- exc_bad_access(code=1, address=0x789870)野指针错误
原因: exc_bad_access(code=1, address=0x789870)野指针错误,主要的原因是,当某个对象被完全释放,也就是retainCount,引用计数为0后.再去通过该对象去调 ...
- (三)原生JS实现 - 插件 - 弹出层
创建遮罩层 _createCover: function() { var newMask = document.createElement("div"); newMask.id = ...
- BZOJ 1003 物流运输 (动态规划 SPFA 最短路)
1003: [ZJOI2006]物流运输 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 5590 Solved: 2293 [Submit][Stat ...
- 【android】android中activity的启动模式
在AndroidManifest.xml中配置 <activity android:label="第二个应用" android:name=".Demo2Activi ...