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 ...
随机推荐
- VC 隐藏托盘图标
苦苦寻找的隐藏托盘图标的方法,今天终于搞定,献给大家! #include <atlbase.h> #include <atlconv.h> #include <CommC ...
- Qt编程之通过鼠标滚轮事件缩放QGraphicsView里面的Item
首先自己subclass QGraphicsView的一个类,叫DiagramView,然后重新实现它的滚轮事件函数,然后发送一个缩放信号: oid DiagramView::wheelEvent(Q ...
- 转:什么是CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?
什么是CGI CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上. CGI可以用 ...
- BZOJ1211: [HNOI2004]树的计数
1211: [HNOI2004]树的计数 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1245 Solved: 383[Submit][Statu ...
- CodeForces 19D Points
Pete and Bob invented a new interesting game. Bob takes a sheet of paper and locates a Cartesian coo ...
- Window的匿名Closing 事件
group.Closing += (sender, e) => { try { Code here } } catch (Exception ex) { Exception here } } ...
- poj 3104 Drying(二分搜索之最大化最小值)
Description It is very hard to wash and especially to dry clothes in winter. But Jane is a very smar ...
- hdu 5159 Card (期望)
Problem Description There are x cards on the desk, they are numbered from 1 to x. The score of the c ...
- hdu 5396 Expression(区间dp)
Problem Description Teacher Mai has n numbers a1,a2,⋯,anand n−1 operators("+", "-&quo ...
- 文件夹65ad47d7-2e27-4a5c-b238-26643fdaeb98
这几天发现电脑中毒了,本地开的服务预览页面时,页面会被插入Html代码.我用360扫描之后发现有木马病毒(c:\programData有个65ad47d7-2e27-4a5c-b238-26643fd ...