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\n", ans);
}
sc.close();
}
}
782B The Meeting Place Cannot Be Changed(二分)的更多相关文章
- Codeforces 782B The Meeting Place Cannot Be Changed(二分答案)
题目链接 The Meeting Place Cannot Be Changed 二分答案即可. check的时候先算出每个点可到达的范围的区间,然后求并集.判断一下是否满足l <= r就好了. ...
- 782B. The Meeting Place Cannot Be Changed 二分 水
Link 题意:给出$n$个坐标$x_i$,$n$个速度$v_i$问使他们相遇的最短时间是多少. 思路:首先可肯定最终相遇位置必定在区间$[0,max(x_i)]$中,二分最终位置,判断左右部分各自所 ...
- CodeForces 782B The Meeting Place Cannot Be Changed (二分)
题意:题意:给出n个人的在x轴的位置和最大速度,求n个人相遇的最短时间. 析:二分时间,然后求并集,注意精度,不然会超时. 代码如下: #pragma comment(linker, "/S ...
- Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)
The Meeting Place Cannot Be Changed 我发现我最近越来越zz了,md 连调程序都不会了,首先要有想法,之后输出如果和期望的不一样就从输入开始一步一步地调啊,tmd现在 ...
- codeforces 782B The Meeting Place Cannot Be Changed (三分)
The Meeting Place Cannot Be Changed Problem Description The main road in Bytecity is a straight line ...
- codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)
B. The Meeting Place Cannot Be Change ...
- CodeForces - 782B The Meeting Place Cannot Be Changed(精度二分)
题意:在一维坐标轴上,给定n个点的坐标以及他们的最大移动速度,问他们能聚到某一点处的最短时间. 分析: 1.二分枚举最短时间即可. 2.通过检查当前时间下,各点的最大移动范围之间是否有交集,不断缩小搜 ...
- codeforces 782B - The Meeting Place Cannot Be Changed
time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standa ...
- CodeForce-782B The Meeting Place Cannot Be Changed(高精度二分)
https://vjudge.net/problem/CodeForces-782B B. The Meeting Place Cannot Be Changed time limit per tes ...
随机推荐
- sql语句如何查询当天,一周,一月的数据的语句
sql查询当天,一周,一个月数据的语句 --查询当天: select * from info where DateDiff(dd,datetime,getdate())=0 --查询24小时内的: ...
- 基于PHP自带的mail函数实现发送邮件以及带有附件的邮件功能
PHPmail函数简介 bool mail ( string $to , string $subject , string $message [, string $additional_headers ...
- E20171108-hm
breadcrumb n. 面包屑:面包心; 2.面包的松软(或柔软)部分; n. 网页导航区(a -> b -> c)
- 洛谷P1010 幂次方
题目描述 任何一个正整数都可以用2的幂次方表示.例如 137=2^7+2^3+2^0 同时约定方次用括号来表示,即a^b 可表示为a(b). 由此可知,137137可表示为: 2(7)+2(3)+2( ...
- 386 Lexicographical Numbers 字典序排数
给定一个整数 n, 返回从 1 到 n 的字典顺序.例如,给定 n =1 3,返回 [1,10,11,12,13,2,3,4,5,6,7,8,9] .请尽可能的优化算法的时间复杂度和空间复杂度. 输入 ...
- js易混API汇总
一:slice()方法 ————————————http://www.w3school.com.cn/jsref/jsref_slice_string.asp ———————————————————— ...
- 不讲CRUSH的Ceph教程是不完整的
前面我们提到了Ceph是一个支持统一存储架构的分布式存储服务.简单介绍了Ceph的基本概念和基础架构包含的组件,其中最重要的就是底层的RADOS和它的两类守护进程OSD and Monitor.上篇文 ...
- mybatis使用中类属性名和数据库表字段名问题
起初我以为上述二者必须一致,后来发现也是可以像Hibernate那样在xml文件中进行映射的. <mapper namespace="com.tenghu.mybatis.model. ...
- string与int的相互转换C++(转)
string与int之间的相互转换C++(转) #include<iostream> #include<string> #include<sstream> usin ...
- jQuery中$this和$(this)的区别
要写一个点击弹窗任意地方,关闭弹窗.点击事件写标签在元素上 onclick = closepop(this),这时候很容易搞不清楚怎么去获取当前元素 function closepop(e){ va ...