D. As Fast As Possible

参考:https://blog.csdn.net/keyboardmagician/article/details/52769493

题意:

一群大佬要走L米,途中可以直接上车,大佬的速度为v1,车的速度为v2,车的位子有限,问大佬们到终点的时间最快是多少。

每个人只能坐一次车。

思路:

这类奥数题真难。有一个比较重要的转化,就是在设定的t时间下,公交车的时间就是全部大佬到终点的时间。

每个人只能坐一次车,所以最后到达终点的人决定总时间,可以看出,用车每次载k个人,行走一定的距离,然后折返载下一趟人追上上一趟的人这种情

况能得出最优值。所以假设第一趟车载人时间为t1,所以两边的人相距v2*t1-v1*t1,假设第二趟车载人时间为t2,因为要追上上一趟,所以v2*t1-v1*t1+v1*t2=v2*t2,

所以t1=t2,也就是每人坐车的时间相等。

车载人的趟数:p=(n+k-1)/k。

设总时间为t,每人坐车的时间t1,则v1*(t-t1)+v2*t1=l,所以t1可以用t表示,设折返时间为t2,则(v2-v1)*t1=(v2+v1)*t2,而且t2*(p-1)+t1*p<=t。

这样二分时间t就好了。

感觉涉及double的二分,最好用for去二分。

#include <algorithm>
#include <iterator>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <iomanip>
#include <bitset>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <list>
#include <map>
#include <set>
using namespace std;
//#pragma GCC optimize(3)
//#pragma comment(linker, "/STACK:102400000,102400000") //c++
#define lson (l , mid , rt << 1)
#define rson (mid + 1 , r , rt << 1 | 1)
#define debug(x) cerr << #x << " = " << x << "\n";
#define pb push_back
#define pq priority_queue typedef long long ll;
typedef unsigned long long ull; typedef pair<ll ,ll > pll;
typedef pair<int ,int > pii;
typedef pair<int,pii> p3; //priority_queue<int> q;//这是一个大根堆q
//priority_queue<int,vector<int>,greater<int> >q;//这是一个小根堆q
#define fi first
#define se second
//#define endl '\n' #define OKC ios::sync_with_stdio(false);cin.tie(0)
#define FT(A,B,C) for(int A=B;A <= C;++A) //用来压行
#define REP(i , j , k) for(int i = j ; i < k ; ++i)
//priority_queue<int ,vector<int>, greater<int> >que; const ll mos = 0x7FFFFFFF; //
const ll nmos = 0x80000000; //-2147483648
const int inf = 0x3f3f3f3f;
const ll inff = 0x3f3f3f3f3f3f3f3f; //
const int mod = 1e9+; const double PI=acos(-1.0); template<typename T>
inline T read(T&x){
x=;int f=;char ch=getchar();
while (ch<''||ch>'') f|=(ch=='-'),ch=getchar();
while (ch>=''&&ch<='') x=x*+ch-'',ch=getchar();
return x=f?-x:x;
}
// #define _DEBUG; //*//
#ifdef _DEBUG
freopen("input", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
/*-----------------------showtime----------------------*/
const int maxn = 1e6+;
int cnt;
int n,l,v1,v2,k;
bool check(double x){ //问题转化为判断公交车的总运行时间
double t1 = (l - v1*x)*1.0 / (v2- v1);
double t2 = (v2 - v1)*1.0*t1/(v1+v2);
return t1 * cnt + t2 * (cnt-) < x;
}
int main(){ scanf("%d%d%d%d%d",&n,&l,&v1,&v2,&k);
if(v1>=v2){
printf("%.8f",l*1.0/v1);
}
else {
cnt = n/k; if(n%k) cnt++;
double le = ,ri = l*1.0 / v1,ans;
for(int i=; i<= ; i++){
double mid = (le + ri)/2.0;
if(check(mid)){
ans = mid;
ri = mid;
}
else le = mid;
}
printf("%.12f\n",ans);
}
return ;
}

Codeforces Round #364 (Div. 2) D. 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

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

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

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

  5. Codeforces Round #364 (Div. 2)

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

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

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

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

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

  8. Codeforces Round #364 (Div. 2) D 数学/公式

    D. As Fast As Possible time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. Codeforces Round #364 (Div. 1)(vp) 没什么题解就留坑待填

    我就做了前两题,第一题第一次vp就把我搞自闭跑路了,第二题第二次又把我搞自闭了 A. As Fast As Possible 细节题 #include<cstdio> #include&l ...

随机推荐

  1. 脱壳系列_0_FSG壳_详细版

    ---恢复内容开始--- 1 查看信息 使用ExeInfoPe查看此壳程序 可以看出是很老的FSG壳. 分析: Entry Point : 000000154,熟悉PE结构的知道,入口点(代码)揉进P ...

  2. 【转】解决eclipse连接不到genymotion的问题

    (1)很多朋友在使用genymotion开发安卓应用程序的时候,会遇见完全正确的安装但是在运行的时候仍然找不到,genymotion上的设备,在打开的devices上找不到如下图所示: (2)解决的方 ...

  3. Dubbo源码学习之-服务导出

    前言 忙的时候,会埋怨学习的时间太少,缺少个人的空间,于是会争分夺秒的工作.学习.而一旦繁忙的时候过去,有时间了之后,整个人又会不自觉的陷入一种懒散的状态中,时间也显得不那么重要了,随便就可以浪费掉几 ...

  4. 插入Oracle数据库后返回当前主键id

    最近做一个spring版本3.0.4的老项目功能,应用场景要用到插入oracle表后返回主键ID拿来和其他表关联. 用oralce的可以一直用这种处理方式,高兼容低,搜索网上的资料都不能和这个Spri ...

  5. Fork 多进程 模拟并行访问web service获取响应时间差

    #include <ros/ros.h> #include <iostream> #include <string> #include <cstring> ...

  6. ABP实现EF执行SQL(增删改查)解决方案

    前言 一般情况下,使用EF中的语法可以帮助我们完成绝大部分业务,但是也有特殊的情况需要直接执行的Sql语句.比如,我们的业务过于复杂繁琐,或是有些业务使用EF操作时比较复杂,但是使用的Sql时会很简单 ...

  7. ThreadPoolExecutor线程池的一个面试题

    问题:现有一个线程池,参数corePoolSize = 5,maximumPoolSize = 10,BlockingQueue阻塞队列长度为5,此时有4个任务同时进来,问:线程池会创建几条线程? 如 ...

  8. java实现发短信功能---腾讯云短信

    目录 java实现发短信功能 前言 开发环境 腾讯云 ---短信 代码 效果 结束语 java实现发短信功能 前言 如今发短信功能已经成为互联网公司的标配,本篇文章将一步步实现java发送短信 考察了 ...

  9. 给debian的docker容器添加crontab定时任务

    现在大部分的docke镜像是基于debian # cat /etc/issue Debian GNU/Linux 9 \n \l Docker容器是不支持后台服务的,像systemctl servic ...

  10. C# 读取CAD文件缩略图(DWG文件)

    //C# 读取CAD文件缩略图(DWG文件) https://blog.csdn.net/hanghangaidoudou/article/details/8589574 //2010-09-04 1 ...