题解: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个点,需要找到一个点使得每个点到这个点耗时最小,每个点都同时开始,且都拥有自己的速度 题解 ...
随机推荐
- SOP页面跳转设计 RAS AES加密算法应用跨服务免登陆接口设计
SOP页面跳转设计 RAS AES加密算法应用跨服务免登陆接口设计 SOP,是 Standard Operating Procedure三个单词中首字母的大写 ,即标准作业程序,指将某一事件的标准操作 ...
- Java编码规范-字符串与Integer的比较,BigDecimal非空参数
Java编码规范-字符串与Integer的比较,BigDecimal非空参数 package com.example.core.mydemo; import java.math.BigDecimal; ...
- Big Exponential Addition
Big Exponential Addition 给定一非负整数n计算2^n的值,一般而言把 2 乘上 n 次,就能得到答案.然而,当n特别大时,2^n要一次次地乘2可能稍嫌太慢,面对此一巨大问题利用 ...
- Angular项目简单使用拦截器 httpClient 请求响应处理
1:为啥要使用拦截器 httpClient 请求响应处理,其作用我们主要是: 目前我的Angular版本是Angular 17.3,版本中实现请求和响应的拦截处理了.这种机制非常适合添加如身份验证头. ...
- windows系统安装或使用inspect.exe工具
确认是否安装? 结合工具everything,进行搜索 选择对应操作系统的版本,右键->选择打开路径,进到inspect.exe的安装路径,双击打开软件 软件开启后,就会自动开始抓取目前软件界面 ...
- 蚁群算法及 TSP 问题上的应用
群智能(Swarm intelligence) 自然界动物群,称之为群. 群的特征: 相互作用的相邻个体的集合 个体的行为简单,既有竞争又有协作 智能化的集体行为(1+1>2): 个体间不仅能够 ...
- .Net Framework使用Autofac实现依赖注入
.Net Framework使用Autofac实现依赖注入 前言 最近也是找了快2周的工作了,收到的面试邀请也就几个,然后有个面试题目是用asp.net mvc + Entityframework 做 ...
- 一文为你深度解析LLaMA2模型架构
本文分享自华为云社区<[云驻共创]昇思MindSpore技术公开课 大咖深度解析LLaMA2 模型架构>,作者: Freedom123. 一.前言 随着人工智能技术的不断发展,自然语言处理 ...
- vol2以及mimikatz插件安装教程
volatility2安装 https://github.com/volatilityfoundation/volatility git clone https://github.com/volati ...
- Sql Server 按日统计产量
碰到一个这样的需求,需要查询每天的产量,直接 group 是可以分出不同天的产量,但是如果当天没有生产,就会少一条那一天的记录,而不是那一天显示产量为0,这样不方便前端显示曲线. 于是找到下面的办法, ...