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 ...
随机推荐
- Haskell语言学习笔记(64)Lens(4)
安装 lens-tutorial Control.Lens.Tutorial $ cabal install lens-tutorial Installed lens-tutorial-1.0.3 P ...
- Eclipse 安装JavaEE插件
Oxygen版Eclipse 导入项目会自动安装你项目需要的一些插件,但是有时候会安装失败,需要手动安装: 这里以Dynamic Web Project项目为例 打开Eclipse,依次选择Help ...
- 注释和取消注释 程序中的log日志
有点简单,但也是原创哦..亲测有效,期待指正. 更改了log多行的问题.. 例如//Log Util: 一.注释log import java.io.BufferedReader;import ...
- vcf格式简介
1)背景 伴随着大规模的基因分型及测序工程的产生(例如1000 Genomes Project),之前的信息贮存格式例如gff文件它记录了每一个基因的详细信息,其中许多基因信息在基因组之间是共享的,而 ...
- Spring Boot AOP
AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是Spring框架中的一个重要内容,它通 ...
- git的一些常用操作命令
这些操作命令都是从廖雪峰老师的官网上看过后记下来的,以下是廖雪峰老师的官网,大家可以看看,教程不错~ http://www.liaoxuefeng.com/wiki/00137395163059296 ...
- 获取RequestMapping注解中的属性
参考:https://www.cnblogs.com/2013jiutian/p/7294053.html @RequestMapping("/value1") @Controll ...
- cmd命令 从C盘转到D盘
点开始 点运行.输入 CMD 回车.进入DOS提示符状态下.输入 cd\ 回车 表示进入 c:\> 也就是C盘根目录下.输入d: 回车 是进入D盘当前目录,并不一定是根目录.然后cd\ ...
- 【校招面试 之 C/C++】第25题 C++ 智能指针(一)之 auto_ptr
1.智能指针背后的设计思想 我们先来看一个简单的例子: void remodel(std::string & str) { std::string * ps = new std::string ...
- js switch case注意事项
今天写switch的时候发现没有达到预期效果,参照w3school的写法发现语法一致 想了一下,js是弱类型语言,是不是不支持number?试了一下将数字改为字符串,果然可以了 或者可以这样写:swi ...