C. Voltage Keepsake
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

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 .

Examples
input
2 1
2 2
2 1000
output
2.0000000000
input
1 100
1 1
output
-1
input
3 5
4 3
5 2
6 1
output
0.5000000000
Note

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) 收藏的更多相关文章

  1. Tomcat原理 分类: 原理 2015-06-28 19:26 5人阅读 评论(0) 收藏

    Tomcat的模块结构设计的相当好,而且其Web 容器的性能相当出色.JBoss直接就使用了Tomcat的web容器,WebLogic的早期版本也是使用了Tomcat的代码. Web容器的工作过程在下 ...

  2. Hadoop基本原理之一:MapReduce 分类: A1_HADOOP 2014-08-17 19:26 1113人阅读 评论(0) 收藏

    1.为什么需要Hadoop 目前,一块硬盘容量约为1TB,读取速度约为100M/S,因此完成一块硬盘的读取需时约2.5小时(写入时间更长).若把数据放在同一硬盘上,且全部数据均需要同一个程序进行处理, ...

  3. Linux命令 标签: linux 2016-08-01 10:26 508人阅读 评论(0) 收藏

    Linux常用命令 文件.目录的基本操作 ls - 查看文件 cp - 拷贝文件 mv - 移动或重命名文件 rm - 删除文件 touch - 创建空文件或更新文件时间 cd - 改变当前路径 pw ...

  4. 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,说明你 ...

  5. 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 ...

  6. C/C++中const的用法 分类: C/C++ 2015-07-05 00:43 85人阅读 评论(0) 收藏

    const是C语言的关键字,经C++进行扩充,变得功能强大,用法复杂.const用于定义一个常变量(只读变量),当const与指针,引用,函数等结合起来使用时,情况会变得复杂的多.下面将从五个方面总结 ...

  7. 自动化测试工具QTP的使用实例 分类: 软件测试 2015-06-17 00:23 185人阅读 评论(0) 收藏

    1. QTP简介 1.1QTP功能与特点 QTP是QuickTest Professional的简称,是一种自动化软件测试工具.在软件的测试过程中,QTP主要来用来通过已有的测试脚本执行重复的手动测试 ...

  8. 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 ...

  9. short-path problem (Spfa) 分类: ACM TYPE 2014-09-02 00:30 103人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> #include <queue> #i ...

随机推荐

  1. select 中添加option的注意

    在平时写JS中经常要给Select添加option,如果我们把option中的数据用一个字符串来表示: eg: var strOption='<option>1</option> ...

  2. tesseract 4.0 编译安装(CentOS)

    1.安装依赖工具 yum install autoconf automake libtool libjpeg-devel libpng-devel libtiff-devel zlib-devel 2 ...

  3. sql server profiler 的使用

    sql server profiler  是作为监听sql语句执行的软件, 主要是看NTUserName,system是系统的,看自己数据库的名字.

  4. #define宏常量和const常量的区别

    C++ 语言可以用const 来定义常量,也可以用#define 来定义常量.但是前者比后者有更多的优点:(1) const 常量有数据类型,而宏常量没有数据类型.编译器可以对前者进行类型安全检查.而 ...

  5. tf.get_variable()

    1. tf.Variable()W = tf.Variable(<initial-value>, name=<optional-name>)1用于生成一个初始值为initial ...

  6. python之生产者消费者模型

    #Auther Bob #--*--conding:utf-8 --*-- #生产者消费者模型,这里的例子是这样的,有一个厨师在做包子,有一个顾客在吃包子,有一个服务员在储存包子,这个服务员我们就可以 ...

  7. iOS 11 scroll滚动偏移,tableview偏移44,获取view的宽和高

    1. tableview 的头部 有44的偏移量 1>.设置 tableview的 属性 tableView.scrollIndicatorInsets = UIEdgeInsets.zero ...

  8. nginx反向代理架构与安装配置(一)

    这里我们准备四台虚拟机,二台负载均衡(LB01,LB02),二台web服务器(WEB01,WEB02).   这里默认所有软件都安装在/data目录下.   四台虚拟机的初始安装是centos7的最小 ...

  9. 启动apache时,出现httpd: Could not reliably determine the server\'s fully qualified domain name, using 127.0.0.1 for ServerName

    1.通过vi打开apache的配置文件httpd.conf > vi /data/apache/conf/httpd.conf 2.找到#ServerName www.example.com:8 ...

  10. 删除SVN版本控制目录

    @echo On @Rem 删除SVN版本控制目录 @PROMPT [Com] @for /r . %%a in (.) do @if exist "%%a\.svn" rd /s ...