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 ...
随机推荐
- SQL语言的组成
在正式学习SQL语言之前,首先让我们对SQL语言有一个基本认识,介绍一下SQL语言的 组成: 1.一个SQL数据库是表(Table)的集合,它由一个或多个SQL模式定义. 2.一个SQL表由行集构成, ...
- Bootstrap风格登录界面设计样例
参考:http://bootsnipp.com/tags/login Register Page 127.8K 187 Modal Login with jQuery Effects 159. ...
- syslog_test.c 简单的syslog函数
#cat syslog_test.c #include<stdio.h> #include<stdlib.h> #include<syslog.h> int mai ...
- Install and configure sql server 2008 express
http://www.symantec.com/connect/articles/install-and-configure-sql-server-2008-express
- hadoop执行hdfs文件到hbase表插入操作(xjl456852原创)
本例中需要将hdfs上的文本文件,解析后插入到hbase的表中. 本例用到的hadoop版本2.7.2 hbase版本1.2.2 hbase的表如下: create 'ns2:user', 'info ...
- (转载)iOS Framework: Introducing MKNetworkKit
This article is available in Serbo-Croatian, Japanese and German. (Translations in Serbo-Croatian b ...
- [RxJS] Creating Observable From Scratch
Get a better understanding of the RxJS Observable by implementing one that's similar from the ground ...
- UIImagePickerController从拍照、图库、相册获取图片
iOS 获取图片有三种方法: 1. 直接调用摄像头拍照 2. 从相册中选择 3. 从图库中选择 UIImagePickerController 是系统提供的用来获取图片和视频的接口: 用UIImage ...
- Hadoop Failed to set permissions of path
在Eclipse里面写了个測试程序:把HDFS中的数据批量导入到HBase中 写好后,在本地測试遇到了例如以下问题: 14/04/21 16:49:53 WARN util.NativeCodeLoa ...
- sql server 2008 中的架构(schame)理解
机构是属于数据库里面的.在一个数据库中,每一张表都属于一个架构,架构就像是命名空间,把数据库中的表分成不同的组,一个组就是一个命名空间,方便管理