这道题一看就是 二分 板子题。

当然由于精度原因,最好由原来的二分模板转换成这个。

while ((w - t) > 0.000001) {
mid = (t + w) / 2.0 ;
if (check (mid)) w = mid ;
else t = mid ;
}

至于 check 函数,十分简单。二分出的时间 \(t\),先计算每个人能够到达的区间 \([x_i-tv_i \ ,\ x+tv_i]\),再判断是否有公共交集。

判断公共交集更简单,算出最小区间 \(mi\) 和最大区间 \(ma\),如果最大交集 \(ma\) 小于等于最小交集 \(mi\),则成立。

放出代码:

#include <bits/stdc++.h>
#define int long long
using namespace std ;
int n ;
double a [60010] , b [60010] , mid , t , w , bao ;
bool check (double x) {
double ma = 0 , mi = 2e9 ;
for (int i = 1 ; i <= n ; i ++) {
mi = min (mi , a [i] + b [i] * x) ;
ma = max (ma , a [i] - b [i] * x) ;
}
return ma <= mi ;
return 0 ;
}
main () {
ios::sync_with_stdio (false) ;
cin.tie (NULL) ; cout.tie (NULL) ;
cin >> n ;
for (int i = 1 ; i <= n ; i ++)
cin >> a [i] , w = max (w , a [i]) ;
for (int i = 1 ; i <= n ; i ++) cin >> b [i] ;
t = 0 ;
while ((w - t) > 0.000001) {
mid = (t + w) / 2.0 ;
if (check (mid)) w = mid ;
else t = mid ;
}
printf ("%.12lf" , t) ;
return 0 ;
}

注意:由于精度原因,样例数据会差大概 \(\pm 0.1\) 左右,这样子也算对的。

题解:CF780B The Meeting Place Cannot Be Changed的更多相关文章

  1. Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)

    The Meeting Place Cannot Be Changed 我发现我最近越来越zz了,md 连调程序都不会了,首先要有想法,之后输出如果和期望的不一样就从输入开始一步一步地调啊,tmd现在 ...

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

  3. code force 403B.B. The Meeting Place Cannot Be Changed

    B. The Meeting Place Cannot Be Changed time limit per test 5 seconds memory limit per test 256 megab ...

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

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

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

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

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

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

                                                                   B. The Meeting Place Cannot Be Change ...

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

  9. B. The Meeting Place Cannot Be Changed

    B. The Meeting Place Cannot Be Changed time limit per test 5 seconds memory limit per test 256 megab ...

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

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

随机推荐

  1. Flask web项目 gunicorn部署

    Flask web项目 gunicorn部署 安装pip3 install gunicorn 查看版本及是否安装成功flask --versiongunicorn -h ### 需要与app.py启动 ...

  2. StringUtils.join()方法使用

    * StringUtils.join()方法使用 打印输出: * 使用 StringBuilder 进行拼接:张三,李四,王五 * 使用 StringUtils.join 进行拼接:张三,李四,王五 ...

  3. rabbitMq消息接收转换对象,Json解析字符串报错syntax error, expect {, actual string, pos 0, fastjson-version 1.2.62解决

    Expected BEGIN_OBJECT but was STRING at line 1 column 2 path $ syntax error, expect {, actual string ...

  4. ES Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed

    查看日志切分:sed -n '/2022-03-21 01:50:11.785/,/2022-03-21 02:25:01.130/p' test-2022-03-21-1.log > 2203 ...

  5. 记Codes 重新定义 SaaS模式开源免费研发项目管理平台——多事项闭环迭代的创新实现

    1.简介 Codes 重新定义 SaaS 模式 = 云端认证 + 程序及数据本地安装 + 不限功能 + 30 人免费 Codes 是一个 高效.简洁.轻量的一站式研发项目管理平台.包含需求管理,任务管 ...

  6. 查看mongo的bson数据文件

    转载请注明出处: BSON(Binary Serialized Document Format)是MongoDB中用于存储和传输数据的一种二进制形式的存储格式,它基于JSON格式,但比JSON更松散, ...

  7. Debian安装Redis服务

    Debian安装Redis服务 安装命令 apt-get update apt-get install redis-server 等待安装完成 配置密码 编辑Redis的配置文件/etc/redis/ ...

  8. Linux 内核:设备驱动模型(6)设备资源管理

    Linux 内核:设备驱动模型(6)设备资源管理 背景 不要总是用Linux 2.6的风格来写驱动代码了,也该与时俱进一下. 参考:http://www.wowotech.net/device_mod ...

  9. dot net core使用BackgroundService运行一个后台服务

    不管是在控制台程序还是asp.net core程序中,我们经常会有用到一个需要长时间运行的后台任务的需求.通常最直觉的方式是使用Thread实例来新建一个线程,但是这样需要自行管理线程的启动和停止. ...

  10. 写给rust初学者的教程(二):所有权、生存期

    这系列RUST教程一共三篇.这是第二篇,介绍RUST语言的关键概念,主要是所有权和生存期等. 第一篇:写给rust初学者的教程(一):枚举.特征.实现.模式匹配 在写第一篇中的练习代码时,不知道你有没 ...