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. 【Python-Django后端开发】配置静态文件详解!!!

    配置前端静态文件 1. 准备静态文件 2. 指定静态文件加载路径 STATIC_URL = '/static/' # 配置静态文件加载路径 STATICFILES_DIRS = [os.path.jo ...

  2. zmnXAglTcg

    #include <map>#include <cmath>#include <stack>#include <queue>#include <l ...

  3. Linux 常用命令及使用方法

    1.  type   :查询命令 是否属于shell解释器 2.  help  : 帮助命令3.  man : 为所有用户提供在线帮助4.  ls  : 列表显示目录内的文件及目录 -l    以长格 ...

  4. Unity经典游戏编程之:球球大作战

    版权声明: 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客&qu ...

  5. Spring aop 拦截自定义注解+分组验证参数

    import com.hsq.common.enums.ResponseState;import com.hsq.common.response.ResponseVO;import org.aspec ...

  6. 【Java笔记】【Java核心技术卷1】chapter3 D4变量

    package chapter3; public class D4变量 { public static final int BBB=100; //类常量 public static void main ...

  7. 原生JavaScript(js)手把手教你写轮播图插件(banner)

    ---恢复内容开始--- 1.轮播图插件 1.什么是插件: 为已有的程序增加功能 2.插件的特点(为什么要做成一个插件)与注意事项: 1.通用性,可移植性强 2.兼容性:不会对其他代码产生影响 3.创 ...

  8. HashMap这些问题你知道吗?

    HashMap是Java面试中的常考点之一,而且其<Key,Value>结构也是开发中常常用到的结构之一.或许你使用过HashMap,但是你知道下面这些问题吗? HashMap的底层结构是 ...

  9. ABAP 查看采购订单行项目已开票金额和已清金额

    FUNCTION zmm_fm_po_invence. *"----------------------------------------------------------------- ...

  10. threejs 学习之

    主要内容: 使用 threejs 创建 20x20 的网格,鼠标移动时,方块跟随移动,点击时在网格任意位置放置方块,按 shift 时,删除当前位置方块. 流程如下: 创建网格 创建一个与网格同样尺寸 ...