http://codeforces.com/contest/782/problem/B

题意:有n个人,每个人有一个位置和速度,现在要让这n个人都走到同一个位置,问最少需要的时间是多少。

思路:看上去很像二分搜索啊!枚举距离,判断是否有更少的时间,然后发现时间不随着距离单调增减,想起前两天被三分虐了一道题,那就是三分吧。

三分枚举距离,然后判断是否有更少的时间就可以了。比赛时候用了max函数还有精度开太大,超时了,索性直接循环100次。

 #include <bits/stdc++.h>
using namespace std;
#define N 200010
const double eps = 1e-;
double x[N], v[N], res;
int n; double cal(double dis) {
double ans = , tmp = ;
for(int i = ; i <= n; i++)
if(ans < fabs(x[i] - dis) / v[i]) ans = fabs(x[i] - dis) / v[i];
if(res > ans) res = ans;
return ans;
} int main() {
scanf("%d", &n);
double ma = , mi = ;
for(int i = ; i <= n; i++) scanf("%lf", &x[i]), ma = max(ma, x[i]), mi = min(mi, x[i]);
for(int i = ; i <= n; i++) scanf("%lf", &v[i]);
double l = mi, r = ma;
res = ;
for(int i = ; i < ; i++) {
double mid = (l + r) / ;
double midd = (mid + r) / ;
if(cal(mid) > cal(midd)) l = mid;
else r = midd;
}
printf("%.12f\n", res);
return ;
}

Codeforces 782B:The Meeting Place Cannot Be Changed(三分搜索)的更多相关文章

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

  2. Codeforces 782B The Meeting Place Cannot Be Changed(二分答案)

    题目链接 The Meeting Place Cannot Be Changed 二分答案即可. check的时候先算出每个点可到达的范围的区间,然后求并集.判断一下是否满足l <= r就好了. ...

  3. codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)

                                                                   B. The Meeting Place Cannot Be Change ...

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

  5. CodeForces 782B The Meeting Place Cannot Be Changed (二分)

    题意:题意:给出n个人的在x轴的位置和最大速度,求n个人相遇的最短时间. 析:二分时间,然后求并集,注意精度,不然会超时. 代码如下: #pragma comment(linker, "/S ...

  6. CodeForces - 782B The Meeting Place Cannot Be Changed(精度二分)

    题意:在一维坐标轴上,给定n个点的坐标以及他们的最大移动速度,问他们能聚到某一点处的最短时间. 分析: 1.二分枚举最短时间即可. 2.通过检查当前时间下,各点的最大移动范围之间是否有交集,不断缩小搜 ...

  7. 782B. The Meeting Place Cannot Be Changed 二分 水

    Link 题意:给出$n$个坐标$x_i$,$n$个速度$v_i$问使他们相遇的最短时间是多少. 思路:首先可肯定最终相遇位置必定在区间$[0,max(x_i)]$中,二分最终位置,判断左右部分各自所 ...

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

    链接:http://codeforces.com/problemset/problem/782/B 题意: N个点,需要找到一个点使得每个点到这个点耗时最小,每个点都同时开始,且都拥有自己的速度 题解 ...

  9. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) B. The Meeting Place Cannot Be Changed

    地址:http://codeforces.com/contest/782/problem/B 题目: B. The Meeting Place Cannot Be Changed time limit ...

  10. AC日记——The Meeting Place Cannot Be Changed codeforces 780b

    780B - The Meeting Place Cannot Be Changed 思路: 二分答案: 代码: #include <cstdio> #include <cstrin ...

随机推荐

  1. Entity framework 更改模型,新增表

    在Package Manager Console 中运行命令Enable-Migrations 再次运行可以更新 抄袭 在实体类中增加一个属性以后,执行 Update-Database 命令 ,可以更 ...

  2. WPF特效-粒子动画

    原文:WPF特效-粒子动画 WPF实现泡泡龙小游戏效果.     /// -Ball to Ball Collision - Detection and Handling    /// http:// ...

  3. MVVM模式的几个开源框架

    原文:MVVM模式的几个开源框架 实现MVVM的框架有很多,如: • MVVM Light Toolkit: http://mvvmlight.codeplex.com • Microsoft Pri ...

  4. 2017-01-11&2017-01-12

    江门警情协作需求. 连续两天搞到超过十点半,所以今天来一并写一下这两天的记录吧. 1.11号明显的进展算是把通讯调通了,还有重新把协作请求的界面按一开始的设想嵌到主界面中. 2.今天12号貌似进展要大 ...

  5. DLL编写与调用全解

    DLL编写与调用全解 DELPHI学习   2008-12-23 22:52   阅读8   评论0   字号: 大  中  小 第一章 为什么要使用动态链接库(DLL) top 提起DLL您一定不会 ...

  6. Windows 10开发基础——VS2015 Update1新建UWP项目,XAML设计器无法加载的解决

    这次,我们来解决一个问题...在使用Visual Studio 2015 Update 1的时候,新建一个UWP的项目,XAML设计器就会崩,具体异常信息如下图: 解决方法如下:下面圈出的那个路径就按 ...

  7. asp.net文件流下载的代码摘要

    try { var workbook = new XLWorkbook(); if (Workbook != null) { workbook = Workbook; } if (this.Expor ...

  8. 管道通信实例(A程序作为服务器,不断从B程序接收数据,并发送到C程序中)

    A程序作为服务器,不断从B程序接收数据,并发送到C程序中:#include <stdio.h>#include <conio.h> #include <tchar.h&g ...

  9. -bash: /root/java/jdk/bin/java: cannot execute binary file

    错误 -bash: /root/java/jdk/bin/java: cannot execute binary file 错误原因 安装的Linux的版本是32位的,下载的软件是64位,版本不兼容, ...

  10. Qt5.5.0在Windows下静态编译(修改参数以后才能支持XP)good

    测试系统环境: windows 7 编译软件环境: vs2013 + QT5.5.0 [源码地址:http://download.qt.io/official_releases/qt/5.5/5.5. ...