UVA 10385 Duathlon
Problem H
Duathlon
Input: standard input
Output: standard output
Time Limit: 15 seconds
A duathlon is a race that involves running r km and cycling k km. n contestants have entered the race; each contestant has different running and cycling speeds. One of the contestants has bribed the organizers to set r and k so that he can win by the maximum margin. You are to determine if this is possible and, if so, give r and k.
Input
The input file contains several sets of input. The description of each set is given below:
The first line of each set contains an integer t, the total distance of the race, in km. That is, r + k = t. The next line contains an integer n, the number of competitors. For each contestant, a line follows with two real numbers giving the running and cycling speed for that contestant. The last line of input gives the running and cycling speed of the contestant who has bribed the organizers. You may assume t does not exceed 100 km and n does not exceed 20. Input is terminated by end of file. Two consecutive sets may or may not be separated by a blank line.
Output
For each set of input produce one line of output. The output description for each set is given below:
If it is possible to fix the race as describe above, print a message giving r and k accurate to two decimal places, and the amount of seconds by which the cheater will win the race (0 is case some competitor ties him), as in the sample below. If it is not possible, print "The cheater cannot win." There is no blank line between outputs for two consecutive sets.
Sample Input
100
3
10.0 40.0
20.0 30.0
15.0 35.0
100
3
10.0 40.0
20.0 30.0
15.0 25.0
Sample Output
The cheater can win by 612 seconds with r = 14.29km and k = 85.71km.
The cheater cannot win.
对于每个K用方程表示出所有的参赛者的时间。用所有人时的时间减去最后一个人的时间,是一个一元一次的函数,那么问题第一个人和第二个人差距最大就转换为每个对应的X轴的图形最小的那个
发现时凸性函数,上凸就是所求
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <stack>
#include <queue>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define LL long long
#define PI 3.1415926535897932626
using namespace std;
int gcd(int a, int b) {return a % b == 0 ? b : gcd(b, a % b);}
#define MAXN 25
double t,v1[MAXN],v2[MAXN];
int n;
double calcu(double r)
{
double k = t - r;
double ans = 1e8;
double t1 = r / v1[n - 1] + k / v2[n - 1];
for (int i = 0 ; i < n - 1; i++)
{
double tmp = r / v1[i] + k / v2[i];
ans = min(ans,tmp - t1);
}
return ans;
}
int main()
{
while (scanf("%lf",&t) != EOF)
{
scanf("%d",&n);
for (int i = 0 ; i < n ; i ++) scanf("%lf%lf",&v1[i],&v2[i]);
double l = 0 ,r = t;
for (int i = 0 ; i < 100; i++)
{
double midl = l + (r - l) / 3;
double midr = r - (r - l) / 3;
if (calcu(midl) > calcu(midr)) r = midr;
else l = midl;
}
if (calcu(l) < 0.00) printf("The cheater cannot win.\n");
else printf("The cheater can win by %.0lf seconds with r = %.2lfkm and k = %.2lfkm.\n", calcu(l) * 3600, l, t - l);
}
return 0;
}
UVA 10385 Duathlon的更多相关文章
- UVA 10385 - Duathlon(三分法)
UVA 10385 - Duathlon 题目链接 题意:一些运动员,參加铁人两项,跑步r千米,骑车k千米,如今知道每一个人的跑步和骑车速度,问是否能设置一个r和k,保持r + k = t,使得第n个 ...
- 【三分搜索算法】UVa 10385 - Duathlon
题目链接 题意:“铁人三项”比赛中,需要选手在t km的路程里进行马拉松和骑自行车项目.现有n名选手,每位选手具有不同的跑步速度和骑车速度.其中第n位选手贿赂了裁判员,裁判员保证第n名选手一定会取得冠 ...
- 铁人系列 (1) uva 10385
uva 10385 列出n-1个一元方程,对应成单峰函数,所以用三分求解即可. #include <cstdio> #include <cstring> #include & ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
随机推荐
- 学习bash——变量
一.什么是变量 变量:一个字眼,用来替代另一个比较复杂或者是容易变动的数据. 变量的优势:可变性.方便性 二.变量内容的设置 关键词:变量,变量名称,变量的内容(我默认将变量与变量名称等价) 方法:变 ...
- Daily Scrum02 12.02
今天是黑色星期一,虽然大家最近被各种大作业压得身心疲惫,但是团队的凝聚力战胜了一切不快. 看看同志们今天的战绩,是不是又有一种充实感油然而生呢??? By Ryan Mao who? Today? T ...
- Daily Scrum02 12.04
第二轮迭代已经进行到了白热化阶段,大家在被编译搞的水深火热的同时依然没有忘记我们的具有颠覆性的团队项目.虽然第一轮迭代我们的成绩不错,但是一定要克服时间不充裕,任务互相冲突的困难,克服不可避免的舆论压 ...
- lintcode-64-合并排序数组 II
64-合并排序数组 II 合并两个排序的整数数组A和B变成一个新的数组. 注意事项 你可以假设A具有足够的空间(A数组的大小大于或等于m+n)去添加B中的元素. 样例 给出 A = [1, 2, 3, ...
- Mac系统中常用快捷键
刚刚接触IOS系统,收集了一些快捷键和系统指令,以便能更好的学习IOS开发. 一.文件操作 复制:Command + C 粘贴:Command + V 回退:Command + ...
- Python之利用reduce函数求序列的最值及排序
在一般将Python的reduce函数的例子中,通常都是拿列表求和来作为例子.那么,是否还有其他例子呢? 本次分享将讲述如何利用Python中的reduce函数对序列求最值以及排序. 我们用r ...
- BZOJ1407 [Noi2002]Savage 【扩展欧几里得】
题目链接 BZOJ1407 题解 枚举\(m\)用扩欧判即可 #include<algorithm> #include<iostream> #include<cstrin ...
- bzoj进度条
好久没发进度了 这个月没有上个月那么猛,肯能使因为这个月不想水题吧 No. 510 Solved Problems List Solved 368 10001001100210071008101210 ...
- mysql5.7.22以上版本忘记密码时这样修改
1.关闭mysql服务 net stop mysql 2.找到mysql安装路径找到 my.ini 打开在 [mysqld] 下添加 skip-grant-tables 跳过密码校验 3.登陆mysq ...
- 洛谷P1282 多米诺骨牌 (DP)
洛谷P1282 多米诺骨牌 题目描述 多米诺骨牌有上下2个方块组成,每个方块中有1~6个点.现有排成行的 上方块中点数之和记为S1,下方块中点数之和记为S2,它们的差为|S1-S2|.例如在图8-1中 ...