• 782B The Meeting Place Cannot Be Changed(二分)


    链接:http://codeforces.com/problemset/problem/782/B

    题意: N个点,需要找到一个点使得每个点到这个点耗时最小,每个点都同时开始,且都拥有自己的速度

    题解: 对于一个确定的位置,如果耗时最久的点在右边,则这个位置可以往右靠,否则就往左靠,这样,一个二分的解法就形成了

    import java.lang.Math;
    import java.util.Scanner;
    
    public class CodeForces_403_B {
        private static final int N = (int) 6e4 + 10;
        static int a[] = new int[N];
        static int v[] = new int[N];
        static double eps = 1e-6;
    
        public static void main(String args[]) {
            // System.out.println("dfwaed");
            Scanner sc = new Scanner(System.in);
            while (sc.hasNext()) {
                int n = sc.nextInt();
                for (int i = 0; i < n; i++)
                    a[i] = sc.nextInt();
                for (int i = 0; i < n; i++)
                    v[i] = sc.nextInt();
    
                double l = 1, r = Double.MAX_VALUE, tmp = 0, tmp1, ans = 0;
                int tmp2 = 0;
                while (Math.abs(r - l) > eps) {
    
                    double mid = (l + r) / 2;
                    tmp = Double.MIN_VALUE;
                    for (int i = 0; i < n; i++) {
                        tmp1 = Math.abs(a[i] - mid) / v[i];
                        if (tmp1 > tmp) {
                            tmp = tmp1;
                            tmp2 = i;
                        }
                    }
    
                    if ((double) a[tmp2] > mid) {
                        l = mid;
                        ans = tmp;
                    } else
                        r = mid;
                }
                System.out.printf("%.6f
    ", ans);
            }
            sc.close();
        }
    }
  • 相关阅读:
    判断ascii码是什么的函数
    php curl
    js form settimeout
    windows php文件下载地址
    面试(3)
    [读码时间] 显示单击的坐标
    [读码时间] 模拟select控件
    [读码时间] 星级评分
    [读码时间] 事件练习:封闭兼容性添加,删除事件的函数
    [读码时间] 数组方法的使用
  • 原文地址:https://www.cnblogs.com/zsyacm666666/p/6516741.html
Copyright © 2020-2023  润新知