Codeforces Round #364 As Fast As Possible
二分思想,对所要花费的时间进行二分,再以模拟的形式进行验证是否可行。
使用二分法,可以将一个求最优解的问题转化为一个判定问题,优雅的暴力。
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
using namespace std;
typedef long long LL;
const int N = 1008, INF = 0x3F3F3F3F;
#define MS(a, num) memset(a, num, sizeof(a))
#define PB(A) push_back(A)
#define FOR(i, n) for(int i = 0; i < n; i++)
int n, k;
double dis, v1, v2; bool check(double m){
double ti = 0;
int tot = n / k;
if(n % k){
tot++;
}
for(int i = 0; i < tot; i++){
double rem = dis - ti * v1;
if(rem <= (m - ti) * v1){
return true;
}
double len = v1 * (m - ti);
double t2 = (rem - len) / (v2 - v1);
ti += t2;
if(i != tot - 1){
double l2 = rem - len;
ti += l2 / (v1 + v2);
}
if(ti > m){
return false;
} }
return true;
}
int main(){
cin>>n>>dis>>v1>>v2>>k;
if(k >= n){
printf("%.10f\n", dis / v2);
}else{
double l = dis / v2;
double r = dis / v1; for(int i = 0; i < 100; i++){
double m = (l + r)/2;
if(check(m)){
r = m;
}else{
l = m;
}
}
printf("%.10f\n", l);
} return 0;
}
Codeforces Round #364 As Fast As Possible的更多相关文章
- Codeforces Round #364 (Div.2) D:As Fast As Possible(模拟+推公式)
题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...
- Codeforces Round #364 (Div. 2) D. As Fast As Possible
D. As Fast As Possible time limit per test 1 second memory limit per test 256 megabytes input stand ...
- Codeforces Round #364 (Div. 2) D. As Fast As Possible 数学二分
D. As Fast As Possible 参考:https://blog.csdn.net/keyboardmagician/article/details/52769493 题意: 一群大佬要走 ...
- codeforces 700a//As Fast As Possible// Codeforces Round #364(Div. 1)
题意:n个人要运动ll长,有个bus带其中几个人,问最短时间 最后所有人在同一时间到终点是用时最少的.由于搭bus相当于加速,每个人的加速时间应该一样.先计算bus走过的路程route.看第一个人被搭 ...
- 【推导】Codeforces Round #364 (Div. 2) D. As Fast As Possible
一种方法是二分总时间,复杂度O(nlogn). 另外我们可以证明,当所有人同时到达终点的时候,是最优的,因为没有人的时间“浪费”了. 我们又发现,每个人的运动过程总是两段,要么是走路,要么是坐车.于是 ...
- Codeforces Round #364
http://codeforces.com/contest/701 A - Cards 水 // #pragma comment(linker, "/STACK:102c000000,102 ...
- Codeforces Round #364 (Div. 2)
这场是午夜场,发现学长们都睡了,改主意不打了,第二天起来打的virtual contest. A题 http://codeforces.com/problemset/problem/701/A 巨水无 ...
- Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)
题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...
- 树形dp Codeforces Round #364 (Div. 1)B
http://codeforces.com/problemset/problem/700/B 题目大意:给你一棵树,给你k个树上的点对.找到k/2个点对,使它在树上的距离最远.问,最大距离是多少? 思 ...
随机推荐
- net-snmp5.7.3移植到arm-linux平台
net-snmp5.7.3移植到arm-linux平台 本次交叉编译在ubuntu 15.04 64位系统下进行. 准备工作 在编译移植前有几项准备工作需要完成. 1下载net-snmp 5.7.3源 ...
- 21 BasicTaskScheduler基本任务调度器(一)——Live555源码阅读(一)任务调度相关类
21_BasicTaskScheduler基本任务调度器(一)——Live555源码阅读(一)任务调度相关类 BasicTaskScheduler基本任务调度器 BasicTaskScheduler基 ...
- iis不支持下载apk的解决办法
添加mime类型即可 扩展名:".apk", MIME类型:"application/vnd.android.package-archive"
- Nginx 使用 sever 段规则屏蔽恶意 User Agent
相对于 Apache,Nginx 占用的系统资源更少,更适合 VPS 使用.恶意的 User Agent 无处不在,博客更换到 WordPress 没几天,就被 SPAM(垃圾留言)盯上,又被暴力破解 ...
- 【Eclipse】eclipse che 协作开发
http://www.eclipse.org/che/ http://blog.csdn.net/ccfeng2008/article/details/50881024 http://www.osch ...
- Git – Fast Forward 和 no fast foward
Git 很是强大,在体验过rebase的华丽之后,再次发现之前在TFS上遇到的问题一下都有解了.但也印证了Git深入并非易事.这篇就谈下一个容易迷糊的概念:Fast forward. Fast-For ...
- Node.js——Async
一:流程控制 为了适应异步编程,减少回调的嵌套,我尝试了很多库.最终觉得还是async最靠谱. 地址:https://github.com/caolan/async Async的内容分为三部分: 流程 ...
- Sort Transformed Array
Given a sorted array of integers nums and integer values a, b and c. Apply a function of the form f( ...
- 引用外部css文件
<link type="text/css" rel="stylesheet" href="http://files.cnblogs.com/91 ...
- python virtualenv环境运行django
python virtualenv环境运行django 安装前准备 检查pip版本与python版本是否一致 [root@localhost bin]# whereis pip pip: /usr/b ...