The Meeting Place Cannot Be Changed

我发现我最近越来越zz了,md 连调程序都不会了,首先要有想法,之后输出如果和期望的不一样就从输入开始一步一步地调啊,tmd现在输出不一样就知道在那等着,有毛用啊.

【题目链接】The Meeting Place Cannot Be Changed

【题目类型】二分答案

&题解:

二分时间,判断函数比较难想,要先假设所有人都向左走,找到坐标最大的那个,之后在假设所有人都向右走,找到坐标最小的那个,如果最大的<=最小的就行了

&代码:

#include <cstdio>
#include <iostream>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
using ll=long long;
const int maxn= 6e4 +9;
int n,x[maxn],v[maxn];
double eps = 1e-6;
bool ok(double t)
{
double ma=-2e9,mi=2e9;
// printf("mi=%f\n",mi);
for(int i=0;i<n;i++){
ma=max(ma,x[i]-v[i]*t);
mi=min(mi,x[i]+v[i]*t);
// printf("i=%d x[i]=%d v[i]=%d mi=%f\n",i,x[i],v[i],mi);
}
// printf("ma %f mi %f\n",ma,mi);
return ma<=mi;
}
int main()
{
// ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
//freopen("C:\\Users\\Zmy\\Desktop\\in.txt", "r", stdin);
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d",&x[i]);
for(int i=0;i<n;i++) scanf("%d",&v[i]);
double l=0,r=1e9;
while(l-r<=eps){
double mid=(l+r)/2;
if(ok(mid)) r=mid-eps;
else l=mid+eps;
}
printf("%.7f\n",l);
return 0;
}

Cf Round #403 B. The Meeting Place Cannot Be Changed(二分答案)的更多相关文章

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

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

  2. Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)

    链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...

  3. 782B. The Meeting Place Cannot Be Changed 二分 水

    Link 题意:给出$n$个坐标$x_i$,$n$个速度$v_i$问使他们相遇的最短时间是多少. 思路:首先可肯定最终相遇位置必定在区间$[0,max(x_i)]$中,二分最终位置,判断左右部分各自所 ...

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

    题意:题意:给出n个人的在x轴的位置和最大速度,求n个人相遇的最短时间. 析:二分时间,然后求并集,注意精度,不然会超时. 代码如下: #pragma comment(linker, "/S ...

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

  6. Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)

    Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...

  7. Codeforces Round #403 (Div. 1, based on Technocup 2017 Finals)

    Div1单场我从来就没上过分,这场又剧毒,半天才打出B,C挂了好几次最后还FST了,回紫了. AC:AB Rank:340 Rating:2204-71->2133 Div2.B.The Mee ...

  8. CF Round #551 (Div. 2) D

    CF Round #551 (Div. 2) D 链接 https://codeforces.com/contest/1153/problem/D 思路 不考虑赋值和贪心,考虑排名. 设\(dp_i\ ...

  9. CF Round #510 (Div. 2)

    前言:没想到那么快就打了第二场,题目难度比CF Round #509 (Div. 2)这场要难些,不过我依旧菜,这场更是被\(D\)题卡了,最后\(C\)题都来不及敲了..最后才\(A\)了\(3\) ...

随机推荐

  1. [模式匹配] AC 自动机 模式匹配

    广义的模式匹配: https://en.wikipedia.org/wiki/Pattern_matching 字符串模式匹配: https://en.wikipedia.org/wiki/Strin ...

  2. Delphi中DLL初始化和退出处理

    来自delphibbs: zhousy_2000, 时间: 2005-09-13 13:53:00, ID: 3203484 <1>利用Unit的Initalization与Finaliz ...

  3. LeetCode 589 N-ary Tree Preorder Traversal 解题报告

    题目要求 Given an n-ary tree, return the preorder traversal of its nodes' values. 题目分析及思路 题目给出一棵N叉树,要求返回 ...

  4. idea出现无效的源发行版:11

    idea启动的时候报错: 点击->file->project structure->project

  5. 元素class的增、删、查、toggle

    比如有一个元素div <div class="btn user">我是div</div> 之前只知道元素有一个className可以来改动  元素的类名 但 ...

  6. JavaScript、关于元素的offset~和client~

    1.偏移量(offset dimension)   =>offsetLeft(元素距离其父元素左边框(/上边框)的距离) =>offsetTop =>offsetWidth(元素的宽 ...

  7. 关于安装SVN Service 出错 Service 'VisualSVN Server' failed to start. Please check VisualSVN Server log in Event Viewer for more details

    关于安装SVN Service 出错 Service 'VisualSVN Server' failed to start. Please check VisualSVN Server log in ...

  8. SpringBoot-区分不同环境配置文件

    spring.profiles.active=pre application-dev.properties:开发环境 application-test.properties:测试环境 applicat ...

  9. w命令 查看系统负载

    linux命令 w [root@localhost snmp]# w :: up :, user, load average: 0.00, 0.01, 0.05 USER TTY FROM LOGIN ...

  10. Redis入门到高可用(六)—— 字符串

    一.结构和命令 1.字符串键值结构 key是字符串,value可以是字符串.数字.二进制.json等: redis的key和string类型value限制均为512MB. 2.使用场景 ♦️ 缓存 ♦ ...