Codeforces801C Voltage Keepsake 2017-04-19 00:26 109人阅读 评论(0) 收藏
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
————————————————————————————————————
题目给出n台设备每分钟耗电量和初始电量,再给出充电器每分钟提供电量,问最长
能坚持多少时间每台设备都有电
思路:二分所需时间,验证是否够坚持这么久时间,题目的数据很大很大,控制精度
徘徊了无数次TLE和WA之后终于AC了
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue> using namespace std;
#define inf 0x3f3f3f3f3f struct node{
double x,y;
}p[100005];
int n;
double m; bool check(double t)
{ double ans=0;
for(int i=0;i<n;i++)
{
ans+=max(0.0,p[i].x*t-p[i].y);
}
if(ans<=m*t)
return 1;
return 0;
} int main()
{
while(~scanf("%d%lf",&n,&m))
{
double cnt=0;
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
cnt+=p[i].x;
}
if(m>=cnt)
printf("-1\n");
else
{
double l=0,r=inf;
while(r-l>1e-4)
{
double mid=(l+r)/2;
if(check(mid))
l=mid;
else
r=mid;
}
printf("%.10lf\n",l);
}
}
return 0;
}
Codeforces801C Voltage Keepsake 2017-04-19 00:26 109人阅读 评论(0) 收藏的更多相关文章
- Tomcat原理 分类: 原理 2015-06-28 19:26 5人阅读 评论(0) 收藏
Tomcat的模块结构设计的相当好,而且其Web 容器的性能相当出色.JBoss直接就使用了Tomcat的web容器,WebLogic的早期版本也是使用了Tomcat的代码. Web容器的工作过程在下 ...
- Hadoop基本原理之一:MapReduce 分类: A1_HADOOP 2014-08-17 19:26 1113人阅读 评论(0) 收藏
1.为什么需要Hadoop 目前,一块硬盘容量约为1TB,读取速度约为100M/S,因此完成一块硬盘的读取需时约2.5小时(写入时间更长).若把数据放在同一硬盘上,且全部数据均需要同一个程序进行处理, ...
- Linux命令 标签: linux 2016-08-01 10:26 508人阅读 评论(0) 收藏
Linux常用命令 文件.目录的基本操作 ls - 查看文件 cp - 拷贝文件 mv - 移动或重命名文件 rm - 删除文件 touch - 创建空文件或更新文件时间 cd - 改变当前路径 pw ...
- Log4j 2使用教程 分类: B1_JAVA 2014-07-01 12:26 314人阅读 评论(0) 收藏
转载自 Blog of 天外的星星: http://www.cnblogs.com/leo-lsw/p/log4j2tutorial.html Log4j 2的好处就不和大家说了,如果你搜了2,说明你 ...
- How to create your own custom 404 error page and handle redirect in SharePoint 分类: Sharepoint 2015-07-08 00:22 4人阅读 评论(0) 收藏
1. In your MOSS server, make a copy of %systemdrive%\Program Files\Common Files\Microsoft Shared\Web ...
- C/C++中const的用法 分类: C/C++ 2015-07-05 00:43 85人阅读 评论(0) 收藏
const是C语言的关键字,经C++进行扩充,变得功能强大,用法复杂.const用于定义一个常变量(只读变量),当const与指针,引用,函数等结合起来使用时,情况会变得复杂的多.下面将从五个方面总结 ...
- 自动化测试工具QTP的使用实例 分类: 软件测试 2015-06-17 00:23 185人阅读 评论(0) 收藏
1. QTP简介 1.1QTP功能与特点 QTP是QuickTest Professional的简称,是一种自动化软件测试工具.在软件的测试过程中,QTP主要来用来通过已有的测试脚本执行重复的手动测试 ...
- Uniform Generator 分类: HDU 2015-06-19 23:26 11人阅读 评论(0) 收藏
Uniform Generator Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- short-path problem (Spfa) 分类: ACM TYPE 2014-09-02 00:30 103人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> #include <queue> #i ...
随机推荐
- autoface
Autofac 依赖注入框架 使用 2015-08-02 10:20 by jiangys, 36262 阅读, 4 评论, 收藏, 编辑 简介 Autofac是一款IOC框架,比较于其他的IOC框架 ...
- python的读写和写读操作
# 读写操作 (读写操作是正常的)f = open('log',mode='r+',encoding='utf-8') # log是文件名 print(f.read()) f.write(" ...
- swagger ui
You can pull a pre-built docker image of the swagger-ui directly from Dockerhub: docker pull swagger ...
- 大型运输行业实战_day03_2_使用ajax将请求页面与请求数据分离
1.引入jquery 1.添加jquery包 2.在要使用jquery的页面中引入jquery 引入jquery后必须检查是否引入正确,这里值得注意的是 springMVC默认情况先会拦截 js文件, ...
- InnoDB FULLTEXT
1.概要 InnoDB引擎对FULLTEXT索引的支持是MySQL5.6新引入的特性,之前只有MyISAM引擎支持FULLTEXT索引.对于FULLTEXT索引的内容可以使用MATCH()…AGAIN ...
- springboot 面向切面
@Aspect @Configuration public class AspectTest { @Pointcut("execution(public String xxx.xxx.xxx ...
- IIS上发布站点后URL重写失效的解决方法
在发布网站时URL重写有可能会失效,如果失效的话就需要您设置一下IIS:1.Windows XP系统或Windows 2003系统等使用以下方法:>打开IIS,主目录-〉配置-〉映射-〉在窗体左 ...
- python模块之time模块
import time #从1970年1月1号凌晨开始到现在的秒数,是因为这一年unix的第一个商业版本上市了,这个最常用# print(time.time()) # 1491574950.23983 ...
- 利用redis完成自动补全搜索功能(一)
最近要做一个搜索自动补全的功能(目前只要求做最前匹配),自动补全就是自动提示,类似于搜索引擎,再上面输入一个字符,下面会提示多个关键词供参考,比如你输入 nb 2字符, 会自动提示nba,nba录像, ...
- ADF backing Bean中常用的代码
// 刷新iterator bindings.refreshControl(); iterBind.executeQuery(); iterBind.refresh(DCIteratorBinding ...