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. Java程序猿的书面采访String3

    public class SameString { //思想二:每个字符都相应着自己的ASC码,第一个思想的算法复杂度为O(nlogn).一般能够利用空间来减少时间复杂度 //能够开辟一个大小为256 ...

  2. WMWaire使用FreeNAS硬盘挂载、Raid0

    FreeNAS硬盘挂载.Raid0 发表于2012 年 03 月 28 日由admin 创建成功,FreeBSD的Hardware显示状态 今天,我们将在VMware工具的帮助下,学习“FreeNAS ...

  3. php 将一个二维数组中两个相同的value 相同 指定值相加

    array(3) { [0]=> array(7) { ["mlid"]=> int(1) ["num"]=> int(1) ["c ...

  4. C#基础:ref和out的区别 [转]

    ref和out的区别在C# 中,既可以通过值也可以通过引用传递参数.通过引用传递参数允许函数成员更改参数的值,并保持该更改.若要通过引用传递参数, 可使用ref或out关键字.ref和out这两个关键 ...

  5. 专门用于消息回调窗口的窗口标识HWND_MESSAGE(创建一个非可视、没有z-order的窗口)

    HWND_MESSAGE Message-Only Windows A message-only window enables you to send and receive messages. It ...

  6. vs2017 js cordova + dotnet core 开发app

    原文:vs2017 js cordova + dotnet core 开发app 1.记得在index.html加入 <meta http-equiv="Content-Securit ...

  7. Linux杂谈: 树形显示多级目录--tree

    最近写博客的时候偶尔会需要将文件目录结构直观地列出来,例如python的包结构. 于是在网上搜了搜,发现了一个Linux下还不错的工具--tree tree 可以很直观地显示多级目录结构. 1. 安装 ...

  8. 【Windows10 IoT开发系列】配置篇

    原文:[Windows10 IoT开发系列]配置篇 Windows10 For IoT是Windows 10家族的一个新星,其针对不同平台拥有不同的版本.而其最重要的一个版本是运行在Raspberry ...

  9. UWP -- Background Task 深入解析

    原文:UWP -- Background Task 深入解析 1. 重点 锁屏问题 从 Windows 10 开始,用户无须再将你的应用添加到锁屏界面,即可利用后台任务,通用 Windows 应用必须 ...

  10. MotionManager 陀螺仪实现方式

      题外话:   权利的游戏开播了,引用一句话:   布兰:一个人如果还把,他还能勇敢么?   奈德:人在害怕时候的勇敢,才是真的勇敢.     回归正题:   说下关于 CMMotionManage ...