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个点对,使它在树上的距离最远.问,最大距离是多少? 思 ...
随机推荐
- Linux下多网卡同网段多IP网络分流设定方法
Linux下多网卡同网段多IP网络分流设定方法 -- :: 标签:Linux下多网卡同网段多IP网络分流设定方法 当服务器需要较高的网络流量时,在其它资源不造成瓶颈的情况下无疑会用到多网卡. 第1选项 ...
- ubuntu下ssh使用proxy:corkscrew
1,安装corkscrew: sudo apt-get install corkscrew 2, 配置 vim ~/.ssh/config 写入如下: Host 10.1.*.* ProxyComma ...
- AutoMapper Getting started
AutoMapper 是什么? 为什么要用AutoMapper? 如何使用AutoMapper? 在什么地方配置AutoMapper? 如何测试my mappings? AutoMapper 是什么? ...
- Additive Number
Additive number is a string whose digits can form additive sequence. A valid additive sequence shoul ...
- C# 静态函数调用窗体控件
回调函数方法是静态函数,需要调用窗体控件,赋值或取值. 定义 public static Form1 mainFrm; mainFrm = this; public partial class F ...
- gcc-5.4.0 static dwarf2 compile
------------------------------------------------------------------------------- 又开始折腾了, 静态编译 gcc-5.4 ...
- C#在类中用调用Form的方法
class 你的类 { private Form1 frm; //构造函数 public 你的类( Form1 form) { frm = form; } //调用form方法 private voi ...
- Effective C++ -----条款41:了解隐式接口和编译期多态
classes和templates都支持接口(interface)和多态(polymorphism). 对classes而言接口是显式的(explicit),以函数签名为中心.多态则是通过virtua ...
- Divide and conquer:Garland(POJ 1759)
挂彩灯 题目大意:就是要布场的时候需要挂彩灯,彩灯挂的高度满足: H1 = A Hi = (Hi-1 + Hi+1)/2 - 1, for all 1 < i < N HN = B Hi ...
- html 中绑定事件 this的指向
var m=function(){ alert(2); } var obj={ A:function(){ }, m:function(){ ...