HDU_1245

这个题目首先要遍历一遍所有的点,将第一次可以到达的点加入到SPFA的队列之中,并设定相应的d[]及step[]的值,其余的d[i]和step[i]都初始化成INF,之后便求出到各个点的最短路以及最短的步数,最后再扫描一遍所有点,把可以跳出lake的点做进一步的处理即可。

#include<stdio.h>#include<string.h>#include<math.h>double d[110],D,x[110],y[110];int step[110],q[110],inq[110],reach[110];double dis(int i,int j){return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));}int main(){int i,j,k,n,N,u,v,ans_s,front,rear;double temp,ans_d;while(scanf("%d%lf",&n,&D)==2)    {        N=0;for(i=0;i<n;i++)        {            scanf("%lf%lf",&x[N],&y[N]);if(x[N]<50.0&&x[N]>-50.0&&y[N]<50.0&&y[N]>-50.0            &&sqrt(x[N]*x[N]+y[N]*y[N])>7.5-1e-7)                N++;        }if(D+1e-7>42.5)        {            printf("42.50 1\n");continue;        }        front=rear=0;        memset(inq,0,sizeof(inq));for(i=0;i<N;i++)        {            temp=sqrt(x[i]*x[i]+y[i]*y[i])-7.5;if(temp<D+1e-7)            {                d[i]=temp;                step[i]=1;                q[rear++]=i;                inq[i]=1;            }else            {                d[i]=1000000001.0;                step[i]=1000000001;            }        }while(front!=rear)        {            u=q[front++];            inq[u]=0;if(front>N)                front=0;for(v=0;v<N;v++)if(u!=v&&dis(u,v)<D+1e-7)                {                    temp=d[u]+dis(u,v);if(temp<d[v]-1e-7)                    {                        d[v]=temp;                        step[v]=step[u]+1;if(!inq[v])                        {                            q[rear++]=v;                            inq[v]=1;if(rear>N)                                rear=0;                        }                    }if(fabs(temp-d[v])<1e-7&&step[u]+1<step[v])                    {                        step[v]=step[u]+1;if(!inq[v])                        {                            q[rear++]=v;                            inq[v]=1;if(rear>N)                                rear=0;                        }                    }                }        }        memset(reach,0,sizeof(reach));for(i=0;i<N;i++)        {            temp=fabs(x[i]+50.0);if(fabs(x[i]-50.0)<temp)                temp=fabs(x[i]-50);if(fabs(y[i]+50.0)<temp)                temp=fabs(y[i]+50);if(fabs(y[i]-50)<temp)                temp=fabs(y[i]-50);if(temp<D+1e-7)                reach[i]=1;            d[i]+=temp;            step[i]++;        }        ans_d=1000000001.0;        ans_s=1000000001;for(i=0;i<N;i++)if(reach[i])            {if(d[i]<ans_d-1e-7)                {                    ans_d=d[i];                    ans_s=step[i];                }if(fabs(d[i]-ans_d)<1e-7&&step[i]<ans_s)                    ans_s=step[i];            }if(ans_d<1000000000.0)            printf("%.2f %d\n",ans_d,ans_s);else            printf("can't be saved\n");    }return 0;    }

HDU 1245 Saving James Bond相关推荐

  1. PTA 06-图2 Saving James Bond - Easy Version (25分)

    题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/672 5-10 Saving James Bond - Easy Version   ( ...

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

  3. Saving James Bond(c++)

    Saving James Bond(c++) 题目描述: This time let us consider the situation in the movie "Live and Let ...

  4. 06-图2 Saving James Bond - Easy Version

    题目来源:http://pta.patest.cn/pta/test/18/exam/4/question/625 This time let us consider the situation in ...

  5. (模拟+floyd)Saving James Bond

    题目: This time let us consider the situation in the movie "Live and Let Die" in which James ...

  6. 图和两种遍历,Saving James Bond

    图可以作为表示指定环境内所有对象的关系的形式.树可以认为是图的子集,图中节点的联系可能是成环的. 图的元素包括边和点,按照不同的需要可能侧重表达点之间的关系或者点本身的信息. int graph[10 ...

  7. 六、图(上):Saving James Bond - Easy Version

    目录 题目描述 代码 注意事项 题目描述 This time let us consider the situation in the movie "Live and Let Die&quo ...

  8. Saving James Bond - Easy Version

    This time let us consider the situation in the movie "Live and Let Die" in which James Bon ...

  9. 中国大学MOOC-陈越、何钦铭-数据结构 Saving James Bond - Easy Version

    题目描述: This time let us consider the situation in the movie "Live and Let Die" in which Jam ...

最新文章

  1. SQLAlchemy实现插入数据(使用前端页面)
  2. 机器学习入门一定要避开的3个陷阱
  3. 畅谈Perl时间处理函数用法
  4. 【十九】require和include的区别
  5. IOS中四种json解析效率比较
  6. java模拟滑动事件_java - 以编程方式在Android视图中触发滑动动作事件 - SO中文参考 - www.soinside.com...
  7. java集合框架的结构_集合框架(Collections Framework)详解及代码示例
  8. python随堂技术演讲时间表
  9. Nest入门教程 - 初识控制器
  10. gradle 项目打包成多个jar包_自从用完 Gradle 后,有点嫌弃 Maven 了!
  11. totolink服务器未响应,TOTOLINK路由器设置后无法上网问题的解决方法
  12. c语言有趣的编程代码,一个有趣的小程序
  13. 全面解析用友网络四位一体数字营销
  14. Floyd最短路径算法
  15. apache poi excel word 加密,不用借助其他jxcell.jar包
  16. 计算机组成原理实验写出下列微指令编码,计算机组成原理实验三.doc
  17. 搭建短域/短链接跳转平台
  18. 夺命雷公狗---DEDECMS----21dedecms按照地区取出电影内容
  19. oracle解锁scott登录,scott怎么解锁并且Oracle数据库登录方法
  20. 【HTTP】10分钟带你快速了解HTTP中常见的状态码(内附大量实例)

热门文章

  1. Elasticsearch5.5.1(核心10)
  2. 负载均衡(SLB)使用最佳实践
  3. 《51单片机应用开发从入门到精通》——2.2 跑马灯实例
  4. 《拥抱变化——社交网络时代的企业转型之道》一构筑社会信任
  5. ExtJS之对话框及窗口篇
  6. RedHat6.5-Linux安装telnet服务
  7. 操作系统学习笔记:进程同步
  8. 文件上传利器SWFUpload使用指南
  9. hp服务器ilo批量配置脚本
  10. iOS走近商城APP(四 runloop应用 获取通讯录并处理)