题解: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个点,需要找到一个点使得每个点到这个点耗时最小,每个点都同时开始,且都拥有自己的速度 题解 ...
随机推荐
- 从零开始写 Docker(十八)---容器网络实现(下):为容器插上”网线“
本文为从零开始写 Docker 系列第十八篇,利用 linux 下的 Veth.Bridge.iptables 等等相关技术,构建容器网络模型,为容器插上"网线". 完整代码见:h ...
- flutter 调用环信sdk 实现即时通讯
首先下载依赖 导包 import 'package:im_flutter_sdk/im_flutter_sdk.dart';登录 import 'package:flutter/material.da ...
- Java邮件发送解决ssl javax.mail实现方式
package test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.activation.DataH ...
- CLR via C# 笔记 -- 字符、字符串、文本处理(14)
1. 字符串一经创建,便不能以任何方式修改,只能修改引用. 2. ToLowerInvariant() 和 ToUpperInvariant() 以忽略语言文化的方式将字符串转换为小写或大写形式.性能 ...
- 修改Git Commit提交记录的用户名Name和邮箱Email
修改Git 本次Commit提交记录的用户名Name和邮箱Email git commit --amend --author="new-name <xxx@new.com>&qu ...
- 79元国产ARM+DSP平台FFT实测分享
T113-i国产ARM+DSP架构介绍 创龙科技SOM-TLT113是一款基于国产全志T113-i双核ARM Cortex-A7 + HiFi4 DSP + 玄铁C906 RISC-V异构多核处理器 ...
- 核对不同文件夹所含内容的差异并提取缺失内容:Python代码
本文介绍基于Python语言,以一个大文件夹作为标准,对另一个大文件夹所包含的子文件夹或文件加以查漏补缺,并将查漏补缺的结果输出的方法. 首先,来明确一下本文所需实现的具体需求.现有一个大文件 ...
- debian12 安装ch343驱动
前言 最近心血来潮,装了一台debian12玩,安装完毕arduino后发现没有ch343驱动,倒是在 ls /lib/modules/6.1.0-13-amd64/kernel/drivers/us ...
- Centos7安装MySQL详细步骤(配置开机自启)
MySQL 检查系统是否安装过mysql //检查系统中有无安装过mysql rpm -qa|grep mysql //查询所有mysql 对应的文件夹,全部删除 whereis mysql find ...
- 使用Stream流实现以List<Map<String, Object>>集合中Map的key值进行排序
使用Stream流实现以List<Map<String, Object>>集合中Map的key值进行排序 创建一个list存入数据 List<Map<String, ...