二分思想,对所要花费的时间进行二分,再以模拟的形式进行验证是否可行。

使用二分法,可以将一个求最优解的问题转化为一个判定问题,优雅的暴力。

#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的更多相关文章

  1. Codeforces Round #364 (Div.2) D:As Fast As Possible(模拟+推公式)

    题目链接:http://codeforces.com/contest/701/problem/D 题意: 给出n个学生和能载k个学生的车,速度分别为v1,v2,需要走一段旅程长为l,每个学生只能搭一次 ...

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

  3. Codeforces Round #364 (Div. 2) D. As Fast As Possible 数学二分

    D. As Fast As Possible 参考:https://blog.csdn.net/keyboardmagician/article/details/52769493 题意: 一群大佬要走 ...

  4. codeforces 700a//As Fast As Possible// Codeforces Round #364(Div. 1)

    题意:n个人要运动ll长,有个bus带其中几个人,问最短时间 最后所有人在同一时间到终点是用时最少的.由于搭bus相当于加速,每个人的加速时间应该一样.先计算bus走过的路程route.看第一个人被搭 ...

  5. 【推导】Codeforces Round #364 (Div. 2) D. As Fast As Possible

    一种方法是二分总时间,复杂度O(nlogn). 另外我们可以证明,当所有人同时到达终点的时候,是最优的,因为没有人的时间“浪费”了. 我们又发现,每个人的运动过程总是两段,要么是走路,要么是坐车.于是 ...

  6. Codeforces Round #364

    http://codeforces.com/contest/701 A - Cards 水 // #pragma comment(linker, "/STACK:102c000000,102 ...

  7. Codeforces Round #364 (Div. 2)

    这场是午夜场,发现学长们都睡了,改主意不打了,第二天起来打的virtual contest. A题 http://codeforces.com/problemset/problem/701/A 巨水无 ...

  8. Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)

    题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...

  9. 树形dp Codeforces Round #364 (Div. 1)B

    http://codeforces.com/problemset/problem/700/B 题目大意:给你一棵树,给你k个树上的点对.找到k/2个点对,使它在树上的距离最远.问,最大距离是多少? 思 ...

随机推荐

  1. Java通过httpclient获取cookie模拟登录

    package Step1; import org.apache.commons.httpclient.Cookie; import org.apache.commons.httpclient.Htt ...

  2. tomcat 访问软连接

    Linux创建软连接: ln -s 源文件 目标文件 tomcat安装目录 / conf目录下的:context.xml文件在 <Context />; 里面加上 allowLinking ...

  3. python查找并删除相同文件-UNIQ File-wxPython版本

    今天用wxPython做了一个GUI程序,我称之为UNIQ File,实现查找指定目录内的相同文件,主要原理是计算文件的md5值(计算前先找出文件大小相同的文件,然后计算这些文件的md5值,而不是所有 ...

  4. htpasswd命令

    htpasswd命令是Apache的Web服务器内置工具,用于创建和更新储存用户名.域和用户基本认证的密码文件. 语法 htpasswd(选项)(参数) 选项 -c:创建一个加密文件:-n:不更新加密 ...

  5. 《oracle每天一练》Merge Into 语句代替Insert/Update在Oracle中的应用实战

    转载自窃破天道 动机: 想在Oracle中用一条SQL语句直接进行Insert/Update的操作. 说明: 在进行SQL语句编写时,我们经常会遇到大量的同时进行Insert/Update的语句 ,也 ...

  6. Longest Increasing Path in a Matrix

    Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...

  7. Sparse Matrix Multiplication

    Given two sparse matrices A and B, return the result of AB. You may assume that A's column number is ...

  8. We7 CMS研究

    我下载的we7 3.0是基于vs 2010的,官方网站也建议使用vs2010,但是我有追新的习惯,并相信vs 2013一定能够兼容vs2010的项目,于是在vs2013下打开解决方案并且全部升级,把目 ...

  9. Linux(CentOS、Ububtu)一键安装Openstack及其它参考文档汇总

    原文链接  http://www.aboutyun.com/thread-10920-1-1.html openstack相关资料 CentOS下一键安装Openstack  http://blog. ...

  10. [C#]Datatable和json互相转换操作

    #region DataTable 转换为Json字符串实例方法 /// <summary> /// GetClassTypeJosn 的摘要说明 /// </summary> ...