触宝第二道算法题,本地AC,提交0%

输出用例 1.00 0.00 中间隔得是 空格 还是 \t ? 我试了都不行呢
全部评论
为什么过不了
点赞
送花
回复
分享
发布于 2017-09-05 20:52
求思路啊
点赞
送花
回复
分享
发布于 2017-09-05 20:13
网易互娱
校招火热招聘中
官网直投
答案发出来大家一起调一调
点赞
送花
回复
分享
发布于 2017-09-05 20:16
拿F12看了一下 是一个空格,但是 还是0% 也没提示什么问题 很懵逼
点赞
送花
回复
分享
发布于 2017-09-05 20:25
import java.util.Scanner; public class Main2 { public static void main(String[] args) {         Scanner in = new Scanner(System.in);         while (in.hasNext()) {         long start=System.currentTimeMillis(); //获取开始时间         int n = in.nextInt();         int[][] a = new int[n][4];         for (int i = 0; i < n; i++) {         a[i][0] = in.nextInt();         a[i][1] = in.nextInt();         a[i][2] = in.nextInt();         a[i][3] = in.nextInt();         }                 Position[] bPos = new Position[n];         double max = Double.MAX_VALUE;         double time = 0.00;                 //time控制到 (t-1, t+1)         for (int t = 0; t < 10; t++) {         //所有点当前位置         for (int i = 0; i < n; i++) {         double x  = a[i][0];         double y  = a[i][1];         double vx = a[i][2];         double vy = a[i][3];         bPos[i] = getPosition(x, y, vx, vy, t);         }         //所有点距离最远的         double length = getMaxLength(bPos);         if (length < max) {         max = length;         time = t;         }         }                 //time控制到 (t-0.1, t+0.1)         for (double t = time - 1.0; t < time + 1.0;) {         //所有点当前位置         for (int i = 0; i < n; i++) {         double x  = a[i][0];         double y  = a[i][1];         double vx = a[i][2];         double vy = a[i][3];         bPos[i] = getPosition(x, y, vx, vy, t);         }         //所有点距离最远的         double length = getMaxLength(bPos);         if (length < max) {         max = length;         time = t;         }         t += 0.1;         }         //找到精确time         for (double t = time - 0.1; t < time + 0.1;) {         //所有点当前位置         for (int i = 0; i < n; i++) {         double x  = a[i][0];         double y  = a[i][1];         double vx = a[i][2];         double vy = a[i][3];         bPos[i] = getPosition(x, y, vx, vy, t);         }         //所有点距离最远的         double length = getMaxLength(bPos);         if (length < max) {         max = length;         time = t;         }         t += 0.01;         }         System.out.println(String.format("%.2f", time) + " " + String.format("%.2f", Math.sqrt(max)));             //要测试的程序或方法         long end=System.currentTimeMillis(); //获取结束时间         System.out.println("程序运行时间: "+(end-start)+"ms");          } } static class Position { double x; double y; public Position(double x, double y) { this.x = x; this.y = y; } } static Position getPosition(double x, double y, double vx, double vy, double t) { double posX = x + t * vx; double posY = y + t * vy; Position position = new Position(posX, posY); return position; } static double getLength(Position pos1, Position pos2) { double x = pos1.x - pos2.x; double y = pos1.y - pos2.y; return x * x + y * y; } static double getMaxLength(Position[] positions) { double max = 0.00; for (int i = 0; i < positions.length - 1; i++) { for (int j = i; j < positions.length; j++) { double length = getLength(positions[i], positions[j]); if (length > max) { max = length; } } } return max; } }
点赞
送花
回复
分享
发布于 2017-09-05 21:07

相关推荐

点赞 2 评论
分享
牛客网
牛客企业服务