codeforces 701 D. As Fast As Possible(数学题)

题目链接:http://codeforces.com/problemset/problem/701/D

题意:给你n个人,每个人走路的速度v1,有一辆车速度为v2,每次可以载k个人,总路程为l,每个人只能上一次车,问最少需要多少时间把所有人送到终点

题解:首先要使的时间最短肯定是所有人同时到达终点,那么肯定每人坐车的时间是相同的。

不妨设一下车一趟来回的时间为t,乘车距离为a。可以得到

(l-a)/v1+a/v2=t*(gg-1)+a/v2(意思就是最后一批人乘车到达终点时所有人同时到达终点)

也就是说我们要求的是(l-a)/v1+a/v2,那么就要把a表示出来。

t*v1=a-(t-a/v2)*v2(在车来回的这段时间里剩下的人走了t*v1,(t-a/v2)*v2表示车回来开了多远的路)

结合两个式子可以得到a=l*(v1+v2)/(v1+v2+2*v1(gg-1))

然后就可以得到答案了。

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main() {
    int n , l , v1 , v2 , k;
    scanf("%d%d%d%d%d" , &n , &l , &v1 , &v2 , &k);
    int gg = n / k + (n % k ? 1 : 0);
    double a = 1.0 * l * (v1 + v2) / (1.0 * (v1 + v2 + 2 * v1 * (gg - 1)));
    printf("%.10lf\n" , a / (1.0 * v2) + (1.0 * l - a) / (1.0 * v1));
    return 0;
}
时间: 2024-11-06 07:36:24

codeforces 701 D. As Fast As Possible(数学题)的相关文章

Codeforces 866C Gotta Go Fast - 动态规划 - 概率与期望 - 二分答案

You're trying to set the record on your favorite video game. The game consists of N levels, which must be completed sequentially in order to beat the game. You usually complete each level as fast as possible, but sometimes finish a level slower. Spec

Codeforces Round #364 As Fast As Possible

二分思想,对所要花费的时间进行二分,再以模拟的形式进行验证是否可行. 使用二分法,可以将一个求最优解的问题转化为一个判定问题,优雅的暴力. #include<cstdio> #include<iostream> #include<cstdlib> #include<cstring> #include<string> #include<algorithm> #include<map> #include<queue>

codeforces 894B - Ralph And His Magic Field - [数学题]

题目链接:https://cn.vjudge.net/problem/CodeForces-894B Ralph has a magic field which is divided into n?×?m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't alway

Codeforces Round #261 (Div. 2) 459B. Pashmak and Flowers(数学题,组合)

题目链接:http://codeforces.com/problemset/problem/459/B B. Pashmak and Flowers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak decided to give Parmida a pair of flowers from the garden.

Codeforces Round #261 (Div. 2)459A. Pashmak and Garden(数学题)

题目链接:http://codeforces.com/problemset/problem/459/A A. Pashmak and Garden time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pashmak has fallen in love with an attractive girl called Parmida s

Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put o

codeforces #364d As Fast As Possible

题意:一群学生,要到离这里为l的地方去.有一辆车,车只有k个座位.人和车的速度分别v1,v2,问你所有人到达的最小时间. 思路:数学题.最小时间就是要求所有同学同时到达.每个同学最多上一次车.那么显然总路程就是车走一段,人走一段,且每个同学两个距离相等. 那么怎么求呢?设每个人坐车距离为l1,步行就是l-l1,算一下一共需要车来回接多少次学生,记为cnt. 第一组学生上车地点在0处.然后会坐车往前 走l1,车再回来,去接后面的同学. 设第二组同学上车地点在d处.首先在车走到l1处时,所用的时间为

Codeforces Round #258 (Div. 2) A. Game With Sticks(数学题)

题目链接:http://codeforces.com/contest/451/problem/A ---------------------------------------------------------------------------------------------------------------------------------------------------------- 欢迎光临天资小屋:http://user.qzone.qq.com/593830943/ma

组合数学题 Codeforces Round #108 (Div. 2) C. Pocket Book

题目传送门 1 /* 2 题意:每一次任选i,j行字符串进行任意长度前缀交换,然后不断重复这个过程,问在过程中,第一行字符串不同的个数 3 组合数学题:每一列不同的字母都有可能到第一行,所以每列的可能值相乘取模就行了.这题主要坑在题意理解上... 4 */ 5 #include <cstdio> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 #include <map&