Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) C Voltage Keepsake
地址:http://codeforces.com/contest/801/problem/C
题目:
2 seconds
256 megabytes
standard input
standard output
You have n devices that you want to use simultaneously.
The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power stored. All devices can store an arbitrary amount of power.
You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible.
You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 109) — the number of devices and the power of the charger.
This is followed by n lines which contain two integers each. Line i contains the integers ai and bi (1 ≤ ai, bi ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning.
If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power.
Your answer will be considered correct if its absolute or relative error does not exceed 10 - 4.
Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if
.
2 1
2 2
2 1000
2.0000000000
1 100
1 1
-1
3 5
4 3
5 2
6 1
0.5000000000
In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged.
In sample test 2, you can use the device indefinitely.
In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second.
思路:二分时间加check
ps1:二分这种小数选用规定二分100次(2^100)或者更多即可,尽量不要用while(fabs(r-l)>eps)
ps2:二分上线r最少应该是1e10,不然会被hack(比赛结束后看其他人讨论时才知道这个hack点的,一阵后怕,还好我刚好写的是1e10)
#include <bits/stdc++.h> using namespace std; #define MP make_pair
#define PB push_back
typedef long long LL;
typedef pair<int,int> PII;
const double eps=1e-;
const double pi=acos(-1.0);
const int K=1e6+;
const int mod=1e9+; int n,p,a[K],b[K];
double ans;
bool check(double x)
{
double sum=;
for(int i=;i<=n;i++)
{
sum+=max(a[i]*x-b[i],0.0);
if(sum>=x*p+1e-)
return ;
}
return ;
}
int main(void)
{
cin>>n>>p;
for(int i=;i<=n;i++)
scanf("%d%d",a+i,b+i);
double l=,r=1e10;
for(int i=;i<=;i++)
{
double mid=(l+r)/2.0;
if(check(mid))
ans=mid,l=mid;
else
r=mid;
}
if(fabs(ans-1e10)<=1e-)
printf("-1\n");
else
printf("%.8f\n",ans);
return ;
}
Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) C Voltage Keepsake的更多相关文章
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)(A.思维题,B.思维题)
A. Vicious Keyboard time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) D. Volatile Kite
地址:http://codeforces.com/contest/801/problem/D 题目: D. Volatile Kite time limit per test 2 seconds me ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) 题解【ABCDE】
A. Vicious Keyboard 题意:给你一个字符串,里面只会包含VK,这两种字符,然后你可以改变一个字符,你要求VK这个字串出现的次数最多. 题解:数据范围很小,暴力枚举改变哪个字符,然后c ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)
A 每次可以换一个或不换,暴力枚举位置即可 B 模拟 C 二分答案.. 边界可以优化r=totb/(tota-p),二分可以直接(r-l>=EPS,EPS不要太小,合适就好),也可以直接限定二分 ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A B C D 暴力 水 二分 几何
A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!
Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C. Bear and Different Names 贪心
C. Bear and Different Names 题目连接: http://codeforces.com/contest/791/problem/C Description In the arm ...
- Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B - Bear and Friendship Condition 水题
B. Bear and Friendship Condition 题目连接: http://codeforces.com/contest/791/problem/B Description Bear ...
- 【树形dp】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) B. Bear and Tree Jumps
我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是, ...
随机推荐
- UIStoryboard小提示
- (id)instantiateInitialViewController - (id)instantiateViewControllerWithIdentifier:(NSString *)ide ...
- windows下查看dns缓存和刷新缓存
ipconfig /displaydns 显示已有缓存,可能比较大建议 ipconfig /displaydns > C:\Users\SDWQ\Desktop\1.txt 再查看. 强制更新缓 ...
- iOS 开发之 -- UDID和UUID的详解
老实说,搞了几年的ios开发了,对基础的概念,还是不牢固,整天都是为了赶进度而码代码,这里记录一下这两者的区别: UDID的全名为 Unique Device Identifier :设备唯一标识符. ...
- shell脚本学习总结03--别名的使用
1.创建别名 $ alias dms='cd Oracle/Middleware/user_projects/domains/7001_costctl/' $ dms $ dms $ pwd /hom ...
- JVM内存简析
1.程序计数器: 这是一块较小的内存空间,它的作用可以看作是当前线程所执行的字节码的行号指示器,线程私有. 2.Java虚拟机栈: 它是Java方法执行的内存模型,每一个方法被调用到执行完成的过程,就 ...
- 解决 Unable to load native-hadoop library for your platform
安装hadoop启动之后总有警告:Unable to load native-hadoop library for your platform... using builtin-java classe ...
- JqGrid 获取所有数据
jqGrid使用本地数据时,当jqGrid配置的rowNum小于本地总数据量(records属性记录总数据,可以通过records获取到本地总数据量),调用getRowData方法获取到的只是显示的部 ...
- 四 Android Studio打包EgretApp (热更新)
官网教程: http://developer.egret.com/cn/github/egret-docs/Native/native/hotUpdate/index.html 和Eclipse一样, ...
- Python全栈day14(字符串格式化)
一,%字符串格式化 1,使用%s 后面一一对应输入对应的字符串,%s可以接受任何参数 print ("I am %s hobby is zhangsan"%'lishi') pri ...
- HBase简单API
一.使用IDEA的maven工程,工程结构如下: 二.maven的依赖pom.xml文件 <?xml version="1.0" encoding="UTF-8&q ...