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的更多相关文章

  1. hdu 1245 Saving James Bond 策画几何+最短路 最短路求步数最少的路径

    #include<stdio.h> #include<string.h> #include<math.h> #define inf 0x3fffffff #defi ...

  2. Saving James Bond(dijk)

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1245 Saving James Bond Time Limit: 6000/3000 MS (Java ...

  3. 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 ...

  4. Saving James Bond - Easy Version (MOOC)

    06-图2 Saving James Bond - Easy Version (25 分) This time let us consider the situation in the movie & ...

  5. pat06-图4. Saving James Bond - Hard Version (30)

    06-图4. Saving James Bond - Hard Version (30) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...

  6. pat05-图2. Saving James Bond - Easy Version (25)

    05-图2. Saving James Bond - Easy Version (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作 ...

  7. Saving James Bond - Hard Version

    07-图5 Saving James Bond - Hard Version(30 分) This time let us consider the situation in the movie &q ...

  8. 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 ...

  9. PAT Saving James Bond - Easy Version

    Saving James Bond - Easy Version This time let us consider the situation in the movie "Live and ...

随机推荐

  1. Powershell创建数组

    在Powershell中创建数组可以使用逗号. PS C:Powershell> $nums=2,0,1,2 PS C:Powershell> $nums 2 0 1 2 对于连续的数字数 ...

  2. Cmake设置环境变量

    references: http://stackoverflow.com/questions/21047399/cmake-set-environment-variables-from-a-scrip ...

  3. Oracle中对列加密的方法

    Oracle中对列加密的方法 2011-12-22 17:21:13 分类: Linux Oracle支持多种列加密方式: 1,透明数据加密(TDE):create table encrypt_col ...

  4. HDU---4417Super Mario 树状数组 离线操作

    题意:给定 n个数,查询 位置L R内 小于x的数有多少个. 对于某一次查询 把所有比x小的数 ”的位置“ 都加入到树状数组中,然后sum(R)-sum(L-1)就是答案,q次查询就要离线操作了,按高 ...

  5. java 实例化是调用了子类重写方法

    java 实例化时调用了抽象方法或者class里面某个方法,如果子类有重写改方法,实际运行的是子类重写方法 package auto.test; //抽象父类 public abstract clas ...

  6. python使用一个集合代替列表

    """说明:对于一个指定的序列,如果需要获得一个只包含该序列中不重复的序列时,使用以下算法:"""seq=['a','a','b','c', ...

  7. Android: 在WebView中获取网页源码

    1. 使能javascript: ? 1 webView.getSettings().setJavaScriptEnabled(true); 2. 编写本地接口 ? 1 2 3 4 5 final c ...

  8. linux自动交互工具expect,tcl安装和安装包,以及自动互信脚本

    linux自动交互工具expect,tcl安装,以及自动互信脚本 工作中需要对几十台服务器做自动互信,无意中发现expect命令,研究一番. 在网上找了许多资料也没有安装成功,摸索着总算成功了.现分享 ...

  9. 解决 Google 重定向,体验 Google 本味

    想要体验原汁原味的 Google(google.com),下面的方案是我用过的较方便的方案. 欢迎更正及补充 Chrome 扩展 Chrone 商店有一款禁止重定向的扩展 NoCountryRedir ...

  10. C#Equal的使用

    代码如下: public partial class FramMain : Form { public FramMain() { InitializeComponent(); } private vo ...