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 ...
随机推荐
- bzoj 1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富【记忆化搜索+剪枝】
c[x][y]为从(x,y)到(n,m)的最大值,记忆化一下 有个剪枝是因为y只能+1所以当n-x>m-y时就算x也一直+1也是走不到(n,m)的,直接返回0即可 #include<ios ...
- bzoj 1715: [Usaco2006 Dec]Wormholes 虫洞【spfa判负环】
tag是假的,用了及其诡异的方法判负环 正权无向边和负权有向边的图 #include<iostream> #include<cstdio> #include<cstrin ...
- WKWebView 和 UIWebView 允许背景音乐自动播放(记录)
WKWebView WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init]; config.allowsInlin ...
- ASP.NET SQL 总结(2)
Sql常见面试题(总结) 1.用一条SQL语句 查询出每门课都大于80分的学生姓名 name kecheng fenshu 张三 语文 81 张三 数学 ...
- C#结构体+结构体与类的区别
C# 结构(Struct) 在 C# 中,结构是值类型数据结构.它使得一个单一变量可以存储各种数据类型的相关数据.struct 关键字用于创建结构. C# 结构的特点 您已经用了一个简单的名为 Boo ...
- C# 的占位符
static void Main(string[] args) { Console.WriteLine("A:{0},a:{1}",65,97); Console.ReadLine ...
- dubbo与zookeeper学习中的问题
环境: spring5.1.5 dubbo 2.6.2 异常信息: java.lang.NoClassDefFoundError: org/apache/curator/RetryPolicy at ...
- [ CQOI 2014 ] 数三角形
\(\\\) Description 求 \(N\times M\) 的网格图上有多少个格点构成的三角形. 当三点共线的时候我们不认为这是一个三角形. \(n,m\le 10^4\) \(\\\) S ...
- Json-->Newton.Json.dll的使用方法
Newton.Json.dll for .NET2.0 实体1 public class Student { public string ID { get; set; } ...
- python 模块-easygui.buttonbox
2018-03-0315:43:11 ): Yes_or_No = easygui.buttonbox("是否良品?", choices=['Yes', 'No', '退出']) ...