Codeforces 782B:The Meeting Place Cannot Be Changed(三分搜索)
http://codeforces.com/contest/782/problem/B
题意:有n个人,每个人有一个位置和速度,现在要让这n个人都走到同一个位置,问最少需要的时间是多少。
思路:看上去很像二分搜索啊!枚举距离,判断是否有更少的时间,然后发现时间不随着距离单调增减,想起前两天被三分虐了一道题,那就是三分吧。
三分枚举距离,然后判断是否有更少的时间就可以了。比赛时候用了max函数还有精度开太大,超时了,索性直接循环100次。
#include <bits/stdc++.h>
using namespace std;
#define N 200010
const double eps = 1e-;
double x[N], v[N], res;
int n; double cal(double dis) {
double ans = , tmp = ;
for(int i = ; i <= n; i++)
if(ans < fabs(x[i] - dis) / v[i]) ans = fabs(x[i] - dis) / v[i];
if(res > ans) res = ans;
return ans;
} int main() {
scanf("%d", &n);
double ma = , mi = ;
for(int i = ; i <= n; i++) scanf("%lf", &x[i]), ma = max(ma, x[i]), mi = min(mi, x[i]);
for(int i = ; i <= n; i++) scanf("%lf", &v[i]);
double l = mi, r = ma;
res = ;
for(int i = ; i < ; i++) {
double mid = (l + r) / ;
double midd = (mid + r) / ;
if(cal(mid) > cal(midd)) l = mid;
else r = midd;
}
printf("%.12f\n", res);
return ;
}
Codeforces 782B:The Meeting Place Cannot Be Changed(三分搜索)的更多相关文章
- 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 ...
- 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 ...
- codeforces 782B - The Meeting Place Cannot Be Changed
time limit per test 5 seconds memory limit per test 256 megabytes input standard input output standa ...
- CodeForces 782B The Meeting Place Cannot Be Changed (二分)
题意:题意:给出n个人的在x轴的位置和最大速度,求n个人相遇的最短时间. 析:二分时间,然后求并集,注意精度,不然会超时. 代码如下: #pragma comment(linker, "/S ...
- CodeForces - 782B The Meeting Place Cannot Be Changed(精度二分)
题意:在一维坐标轴上,给定n个点的坐标以及他们的最大移动速度,问他们能聚到某一点处的最短时间. 分析: 1.二分枚举最短时间即可. 2.通过检查当前时间下,各点的最大移动范围之间是否有交集,不断缩小搜 ...
- 782B. The Meeting Place Cannot Be Changed 二分 水
Link 题意:给出$n$个坐标$x_i$,$n$个速度$v_i$问使他们相遇的最短时间是多少. 思路:首先可肯定最终相遇位置必定在区间$[0,max(x_i)]$中,二分最终位置,判断左右部分各自所 ...
- 782B The Meeting Place Cannot Be Changed(二分)
链接:http://codeforces.com/problemset/problem/782/B 题意: N个点,需要找到一个点使得每个点到这个点耗时最小,每个点都同时开始,且都拥有自己的速度 题解 ...
- 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 ...
随机推荐
- “TNS-03505:无法解析名称”问题解决一例
1. 问题情境 开发人员,在windows新环境ORACLEclient.配置"tnsnames.ora"后,准备连接Linux环境的ORACLE数据库,使用tnsping报TN ...
- WebAPI Delete方法报错405 Method Not Allowed
.net framework 在Web.config文件中添加如下配置: <system.webServer> <modules runAllManagedModulesForAll ...
- XF 表视图添加和删除行
using System;using Xamarin.Forms;using Xamarin.Forms.Xaml; [assembly: XamlCompilation (XamlCompilati ...
- C/C++ static用法
这篇文章没有太多的实际内容,简单记录下static的用法.顺便试一下用markdown来写文章. 1. 在函数中使用 我们都知道在一个函数中的变量是存储在栈区中,函数的每一次调用都伴随着变量的重新定义 ...
- C# 优先级队列
前6行是优先队列,后6行是C#原生的queue Min Heap Priority Queue Works with: C# version 3.0+/DotNet 3.5+ The above co ...
- 指定Qt程序运行的style,比如fusion(以前没见过QStyleFactory)
转载请注明文章:指定Qt程序运行的style,比如fusion 出处:多客博图 代码很简单,如下: #include <QtWidgets/QApplication> #include ...
- So Good They Can't Ignore You
总体而言,这本书的作者的观点就是,你只有做好了,才会有兴趣,而不是一开始就找可能并不存在的所谓兴趣——好多人就败在不停地找这么一个根本就不存在的兴趣.这个观点简直就是拯救那些乔布斯的粉丝:Follow ...
- /\B(?=(?:\d{3})+$)/g 一条令人费解的正则表达式
网上浏览博客看到要用JavaScript正则表达式解决一个功能, 要在数字中间插入逗号, 用来表示书面的金额写法. JS代码是这样子的 let test1 = '1234567890' let for ...
- 基于Monte Carlo方法的2048 A.I.
2048 A.I. 在 stackoverflow 上有个讨论:http://stackoverflow.com/questions/22342854/what-is-the-optimal-algo ...
- select Demo
#include <iostream> #include <WinSock2.h> using namespace std; #pragma comment(lib, &quo ...