编程语言:Java
题目:

题解:路径还原罢了,每次跳到下一个点的时候记录一下就可以了,还以为能一次过,结果竟然可以一次跳到岸上(咱们强大的詹姆斯·邦德~~),也不想去优化程序了,直接一个外部条件判断解决;一个参数的distance是第一次跳的距离,后面的是判断两点之间的距离;此外,题目还有一个要求,在有很多最短路径的时候选择第一条最短的,解决方法就是按到岸的距离的远近来排序,这样还可以提前结束循环(到岸的距离太长了,一次跳不上去,那后面的也跳不上去了呀);最后这道题用Scanner也不会超时的。
结果:AC

import java.io.*;
import java.util.*;
import java.util.concurrent.LinkedBlockingQueue;public class Main {static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));static PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));static Scanner sc = new Scanner(new BufferedInputStream(System.in));static crocodile[] c=new crocodile[102];static boolean[] f=new boolean[102];static int[] prev=new int[102];static double radius=7.5;static int n,d;public static void main(String[] args) throws IOException {in.nextToken();n= (int) in.nval;in.nextToken();d= (int) in.nval;for(int i=1;i<=n;i++){in.nextToken();int x= (int) in.nval;in.nextToken();int y= (int) in.nval;c[i]=new crocodile(x,y);}if(d>=50-radius)out.println(1);else{Arrays.sort(c,1,n+1, new Comparator<crocodile>() {@Overridepublic int compare(crocodile o1, crocodile o2) {return o1.x*o1.x+o1.y*o1.y-o2.x*o2.x-o2.y*o2.y;}});int ways=Integer.MAX_VALUE;Deque<Integer> stack=new LinkedList<>();for(int i=1;i<=n;i++){if(distance(i)){Arrays.fill(prev,-1);Arrays.fill(f,false);point p=bfs(i);if(p!=null&&p.step<ways){stack.clear();stack.push(p.i);while(prev[p.i]!=-1){stack.push(prev[p.i]);p.i=prev[p.i];}ways=p.step;}}else{break;}}if(ways==Integer.MAX_VALUE){out.println(0);}else{out.println(stack.size()+1);while(stack.size()>0){int i=stack.pop();out.println(c[i].x+" "+c[i].y);}}}out.flush();}private static point bfs(int i) {LinkedBlockingQueue<point> que=new LinkedBlockingQueue<>();que.add(new point(i,1));f[i]=true;while(!que.isEmpty()){point p=que.poll();if(Math.abs(c[p.i].x)>=50-d||Math.abs(c[p.i].y)>=50-d)return p;for(int j=1;j<=n;j++){if(!f[j]&&distance(p.i,j)){que.add(new point(j,p.step+1));prev[j]=p.i;f[j]=true;}}}return null;}private static boolean distance(int i) {if(Math.sqrt(c[i].x*c[i].x+c[i].y*c[i].y)<=d+radius)return true;elsereturn false;}private static boolean distance(int i, int j) {int x=c[i].x-c[j].x;int y=c[i].y-c[j].y;if(Math.sqrt(x*x+y*y)<=d)return true;elsereturn false;}}
class point{int i;int step;public point(int i, int step) {this.i = i;this.step = step;}
}
class crocodile{int x;int y;public crocodile(int x, int y) {this.x = x;this.y = y;}
}

Saving James Bond - Hard Version相关推荐

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

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

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

  5. Saving James Bond - Easy Version

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

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

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

  7. 图5 Saving James Bond - Hard Version

    全部每周作业和视频思考题答案和解析 见 浙江大学 数据结构 思考题+每周练习答案 题目:This time let us consider the situation in the movie &qu ...

  8. 算法 图2 Saving James Bond - Easy Version

    全部每周作业和视频思考题答案和解析 见 浙江大学 数据结构 思考题+每周练习答案汇总 题目:This time let us consider the situation in the movie & ...

  9. (c语言)Saving James Bond - Hard Version (30分)

    关于数据结构Mooc后的每一道答案 基本我都已经给出了详解 希望能对大家有所帮助 收藏一下也是方便大家查找吧 希望大家一起进步! (c语言)浙大数据结构Mooc作者答案集 原题题目(谷歌翻译) 全检查 ...

  10. 07-图4. Saving James Bond - Hard Version (30)

    本题测试点5是从小岛范围内可以直接跳到岸边-- 测试点4是验证步数第一跳最小的情况,刚开始没有考虑回溯,所以错了-- #include <stdio.h> #include <str ...

最新文章

  1. JOptionPane的常用4种对话框
  2. vue 虚拟服务器,vue+webpack项目中使用dev-server搭建虚拟服务器,请求json文件数据,实现先后台分离开发...
  3. linux Ubuntu apache2 伪静态设置
  4. 摄影光学与镜头pdf_人类光学精华该不该买?萌新小白的第一支镜头!摄影器材指南!...
  5. 建立网站的全套流程与详细解释(转载)
  6. STM32工作笔记0097---OEM厂是什么意思
  7. dsu on tree(Educational Codeforces Round 2: E. Lomsat gelral)
  8. linux下keepalived+nginx的负载均衡搭建
  9. 基于银河麒麟 V10 系统安装和卸载 DM8 数据库
  10. unity xml反序列化为数据类
  11. maven plugins 飘红问题
  12. 敏捷宣言:四大核心价值观和十二条原则
  13. 高德地图ar步行导航使用教程分享
  14. [MS Project]Project软件入门两天之旅
  15. 基于C#的工控上位机软件开发从入门到学废,需要几步?
  16. PostgreSQL时间加减
  17. 个人登录空间 含登录注册功能
  18. 经典游戏制作教程[小糊涂的灵感]
  19. 依托Airship,ATT走进混合云的世界
  20. php 1075 incorrect,windows无法启动wlan错误1075怎么办

热门文章

  1. 培养人脉的106种方法
  2. Android Studio TraceView性能优化分析
  3. 平面设计师工资怎么样?学平面设计好吗?
  4. quartz.properties自定义位置
  5. Python周刊467期
  6. 【VS code】彩虹括号扩展插件 “Brackets Pair Colorize 2” 安装与自定义颜色
  7. NBUT - 1723 有多少三元组
  8. 泰坦陨落2 - 概念艺术
  9. Parking-lot
  10. IDEA解决“找不到包”或“找不到符号”,但代码没有错误的问题