World Finals 2017
Need for Speed
Sheila is a student and she drives a typical student car: it is old, slow, rusty, and falling apart. Recently, the needle on the speedometer fell off. She glued it back on, but she might have placed it at the wrong angle. Thus, when the speedometer reads ss, her true speed is s+cs+c, where cc is an unknown constant (possibly negative).
Sheila made a careful record of a recent journey and wants to use this to compute cc. The journey consisted of nn segments. In the ithith segment she traveled a distance of didi and the speedometer read sisi for the entire segment. This whole journey took time tt. Help Sheila by computing cc.
Note that while Sheila’s speedometer might have negative readings, her true speed was greater than zero for each segment of the journey.
Input
The first line of input contains two integers nn (1≤n≤10001≤n≤1000), the number of sections in Sheila’s journey, and tt(1≤t≤1061≤t≤106), the total time. This is followed by nn lines, each describing one segment of Sheila’s journey. The ithith of these lines contains two integers didi (1≤di≤10001≤di≤1000) and sisi (|si|≤1000|si|≤1000), the distance and speedometer reading for the ithith segment of the journey. Time is specified in hours, distance in miles, and speed in miles per hour.
Output
Display the constant cc in miles per hour. Your answer should have an absolute or relative error of less than 10−610−6.
Sample Input 1 | Sample Output 1 |
---|---|
3 5 |
3.000000000 |
Sample Input 2 | Sample Output 2 |
---|---|
4 10 |
-0.508653377 |
wa了好久了,搞不懂二分范围,以为-1000到1e6+1000就够了,我一开大范围反而得不到答案
通过读题列出通项公式,很容易想到二分操作
#include<bits/stdc++.h>
#define eps 1e-8
using namespace std;
typedef long long ll;
double a[],b[];
int n,m;
double solve(){
double l=-<<,r=<<,mid;
for(int i=;i<n;i++)
l=max(l,-b[i]);
for(int i=;i<;i++){
mid=(l+r)/;
double sum=0.0;
for(int j=;j<n;j++){
sum+=a[j]/(mid+b[j]);
}
if(sum-m>) l=mid;
else r=mid;
}
return r;
}
int main(){
cin>>n>>m;
for(int i=;i<n;i++)
cin>>a[i]>>b[i];
double ans=solve();
printf("%.8lf\n",ans);
}
World Finals 2017的更多相关文章
- World Finals 2017爆OJ记
Day-Inf: 去年China-Final一道数据结构题的FB送我进WF. 今年课表意外地满,好几天都是早上8点一直上课上到晚上9点,作业也相对较多.敝队大约每个星期只能训练一个下午,有时候甚至一整 ...
- World Finals 2017 (水题题解)
看大佬做2017-WF,我这种菜鸡,只能刷刷水题,勉强维持生活. 赛后补补水题. 题目pdf链接,中文的,tls翻译的,链接在这里 个人喜欢在vjudge上面刷题. E Need for Speed ...
- #6472. 「ICPC World Finals 2017」难以置信的任务 Mission Improbable
可以简化一下问题,假设Patrick把箱子都拿走但是原来有箱子的位置留下一个,现在要放箱子使得每行每列最大值都满足,最少放多少个. 设第\(i\)行的最大值是\(H(i)\),第\(i\)列的是\(W ...
- ZJOI2019一轮游记
Preface 期待已久的省选终于开始了233,关于之前的一些内容,在ZJOI2019一轮停课刷题记录都可以找到,这里不再赘述 ZJOI2019,Bless All Day -1 今天难得有休息,昨晚 ...
- Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals)
Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) 说一点东西: 昨天晚上$9:05$开始太不好了,我在学校学校$9:40$放 ...
- Codeforces Gym 101471D Money for Nothing(2017 ACM-ICPC World Finals D题,决策单调性)
题目链接 2017 ACM-ICPC World Finals Problem D (这题细节真的很多) 把所有的(pi,di)按横坐标升序排序. 对于某个点,若存在一个点在他左下角,那么这个点就是 ...
- Codeforces Round #403 (Div. 1, based on Technocup 2017 Finals)
Div1单场我从来就没上过分,这场又剧毒,半天才打出B,C挂了好几次最后还FST了,回紫了. AC:AB Rank:340 Rating:2204-71->2133 Div2.B.The Mee ...
- [Russian Code Cup 2017 - Finals [Unofficial Mirror]]简要题解
来自FallDream的博客,未经允许,请勿转载,谢谢. Div1难度+ACM赛制 和几个大佬组队逛了逛 A.给一个大小为n的集合ai(1<=ai<=1000000),要求你构造一个大小 ...
- 树的性质和dfs的性质 Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) E
http://codeforces.com/contest/782/problem/E 题目大意: 有n个节点,m条边,k个人,k个人中每个人都可以从任意起点开始走(2*n)/k步,且这个步数是向上取 ...
随机推荐
- 定时任务-Timer
Timer类的全限定名 java.util.Timer java.util.Timer类的构造函数 public Timer(); public Timer(boolean isDaemon); pu ...
- ABC时间管理法
名称 ABC时间管理法 属于 事务优先顺序法的“鼻祖” 做法 将待办的事项按照又重要到轻的顺序划分为A,B,C三个等级,然后按照事项的重要等级依据完成任务的做事方法. 特点 使学习.工作和生活等活动在 ...
- JS语法学习笔记
JS语法: JS知识点一览图 JS知识点一览图 在function中写this,在本function中可以显示,写Person则显示undefined. 在function中写Person,在func ...
- mysql实现计数器
本文转自:https://blog.csdn.net/stevendbaguo/article/details/70889449 如果是在非常高的并发之下,还是建议用内存数据库redis去实现计数的功 ...
- [Rational Rose 2007]解决启动报”解决无法启动此程序因为丢失suite objects.dll“的问题
问题根源1:不是丢失suite objects.dll文件,而是环境变量配置错误或无配置 假如安装目录如:C:\Program Files\Rational 需要配置环境变量的路径为:C:\Progr ...
- NTFS文件系统结构及文件恢复
结构部分参考了 https://www.cnblogs.com/mwwf-blogs/archive/2015/05/04/4467687.html 以及P老师的课件. 文件恢复参考: https: ...
- webuploader项目中多文件上传实例
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 清北学堂2018DP&图论精讲班 DP部分学习笔记
Day 1 上午 讲的挺基础的--不过还是有些地方不太明白 例1 给定一个数n,求将n划分成若干个正整数的方案数. 例2 数字三角形 例7 最长不下降子序列 以上太过于基础,不做深入讨论 例3 给定一 ...
- Bootstrap 原始按钮
Bootstrap 原始按钮 <!DOCTYPE html><html><head><meta http-equiv="Content-Type&q ...
- Spring入门Ioc、DI笔记
Spring是为解决企业应用程序开发复杂性而创建的一个Java开源框架.以下是本人学习过程中总结的一些笔记: 如何学习Spring - 掌握用法 - 深入理解 - 反复总结 - 再次深入理解和实践 s ...