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. [AC自己主动机] zoj Searching the String

    意甲冠军: 到原始字符串.给n字符串,每个字符串都有一个属性,属性0代表重叠,1代表不能重叠 请各多少次出现的字符串 思维: 为了便于建立两台机器自己主动(0一个.1一个) 然后,它可以重叠非常好做, ...

  2. Bootstrap 标签徽章巨幕页头

    @{    Layout = null;}<!DOCTYPE html><html><head>    <meta name="viewport&q ...

  3. XAML的命名空间 - CSDN博客

    原文:XAML的命名空间 - CSDN博客 一个最简单的XAML例子 <Window x:Class="WpfApplication1.MainWindow" xmlns=& ...

  4. php获取一个月前的时间戳,获取三个月前的时间戳,获取一年前的时间戳

    strtotime 非常强大的一个获取时间戳的函数 php获取一个月前的时间戳: strtotime("-0 year -1 month -0 day"); php获取三个月前的时 ...

  5. 图像滤镜艺术---Swirl滤镜

    原文:图像滤镜艺术---Swirl滤镜 Swirl Filter Swirl 滤镜是实现图像围绕中心点(cenX,cenY)扭曲旋转的效果,效果图如下: 原图 效果图 代码如下:         // ...

  6. RSA加密解密及RSA签名和验证

    原文:RSA加密解密及RSA签名和验证 1.RSA加密解密: (1)获取密钥,这里是产生密钥,实际应用中可以从各种存储介质上读取密钥 (2)加密 (3)解密2.RSA签名和验证 (1)获取密钥,这里是 ...

  7. NET C#创建WINDOWS系统用户

    原文:NET C#创建WINDOWS系统用户   /前提是当前用户有相应的权限 /WinNT用户管理 using System; using System.DirectoryServices;  na ...

  8. Add-AppxProvisionedPackage

    原文: Add-AppxProvisionedPackage Adds an app package (.appx) that will install for each new user to a ...

  9. C#实现bitmap图像矫正

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. Delphi xe5调用外部扫描程序——谷歌 zxing

    unit uZXing; interface uses System.SysUtils, System.Types, System.UITypes, System.Classes, System.Va ...