题解:CF780B The Meeting Place Cannot Be Changed
这道题一看就是 二分 板子题。
当然由于精度原因,最好由原来的二分模板转换成这个。
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的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- AC日记——The Meeting Place Cannot Be Changed codeforces 780b
780B - The Meeting Place Cannot Be Changed 思路: 二分答案: 代码: #include <cstdio> #include <cstrin ...
- Codeforces 782B The Meeting Place Cannot Be Changed(二分答案)
题目链接 The Meeting Place Cannot Be Changed 二分答案即可. check的时候先算出每个点可到达的范围的区间,然后求并集.判断一下是否满足l <= r就好了. ...
- codeforces 782B The Meeting Place Cannot Be Changed+hdu 4355+hdu 2438 (三分)
B. The Meeting Place Cannot Be Change ...
- 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 ...
- 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 ...
- 782B The Meeting Place Cannot Be Changed(二分)
链接:http://codeforces.com/problemset/problem/782/B 题意: N个点,需要找到一个点使得每个点到这个点耗时最小,每个点都同时开始,且都拥有自己的速度 题解 ...
随机推荐
- Atcoder Beginner Contest 324 G Generate Arrays 题解-Treap
为了更好的阅读体验,请点击这里 题目链接 套上平衡树板子就能做的很快的题,然后因为是指针存树,因此交换只需要把序列大小较小的挨个拿出来插到相应的地方即可.复杂度 \(O(N \log^2 N)\). ...
- (数据科学学习手札162)Python GIS神器geopandas 1.0版本发布
本文完整代码及附件已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 大家好我是费老师,就在昨天,Python生 ...
- 关于c指针的理解
1 #include<stdio.h> 2 { 3 int a= 100,b=10; 4 int *p1=&a,*p2=&b; 5 *p1=b; 6 *p2=a; 7 pr ...
- Python使用Matplotlib画以日期为X轴的图
Python使用Matplotlib画以日期为X轴的图 步骤: 用pd把字符串格式的日期转成date格式. 使用 AutoDateLocator 设置x轴的属性. 1 from matplotlib ...
- OpenLiveWriter的代码高亮插件
可参考如下方法: https://www.cnblogs.com/mq0036/p/12101912.html 0. 最新插件下载地址:Memento.OLW_V1.0.0.5.7z 1. 找到Ope ...
- Ubuntu访问samba共享文件
Ubuntu访问samba共享文件 参考:https://www.cnblogs.com/Wolf-Dreams/p/11241198.html 做法 安装samba-client.cifs-util ...
- yb课堂之单机和分布式应用的登陆校验解决方案 《七》
单机tomcat应用登陆校验 session保存在浏览器和应用服务器会话之间 用户登陆成功,服务端会保存一个session,当然客户端有一个sessionId 客户端会把sessionId保存在coo ...
- 物联网浏览器(IoTBrowser)-基于计算机视觉开发的应用“智慧眼AIEye”
一.起因 最近毕业在家:),准备筹划社区运营和IoTBrowser升级的事务,遇到了一系列物业管理上的问题,本来出于好心提醒物业人员,结果反被误认为是打广告推销的,当时被激怒一下,后面一想也许这也是一 ...
- 劫持TLS绕过canary && 堆和栈的灵活转换
引入:什么是TLScanary? TLScanary 是一种在 Pwn(主要是二进制漏洞利用)中常见的技术,专门用于处理 TLS 保护的二进制文件.在安全竞赛(例如 CTF)和漏洞利用场景中,攻击者需 ...
- PHP中的__autoload()和spl_autoload_register()
php的__autoload函数是一个魔术函数,在这个函数出现之前,如果一个php文件里引用了100个对象,那么这个文件就需要使用include或require引进100个类文件,这将导致该php文件 ...