当前位置:网站首页>P3743 Kotori's equipment
P3743 Kotori's equipment
2022-07-26 08:43:00 【Tiredd】
Background
kotori Yes nn Devices that can be used at the same time .
Title Description
The first i Devices consume per second ai Unit energy . The use of energy is continuous , In other words, energy is not suddenly consumed at some time , But consume at a constant speed . in other words , For any real number , stay k The energy consumed in seconds is k*ai Company . At the beginning i It is stored in a device bi Unit energy .
meanwhile kotori There is also a power bank that can charge any device , It can charge the connected equipment every second p A unit of , Charging is also continuous , I won't repeat . You can charge any device at any time , The time to switch from one device to another is ignored .
kotori Want to use these devices together , Until the energy of some equipment is reduced to 0. therefore kotori Want to know , Under the action of charger , How long can she use these devices together at most .
Input format
The first line gives two integers n,pn,p.
Next nn That's ok , Each line represents a device , Give two integers , It's the equipment ai and bi.
Output format
If kotori Unlimited access to these devices , Output -1.
Otherwise output kotori In one of the devices, the energy is reduced to 0 How long can I use it before .
sample input :
2 1 2 2 2 1000
sample output :
2.0000000000
sample input :
1 100 1 1
sample output :
-1
Ideas : The question is how long it takes to find the longest , Then it can be divided into two points or dp Think in the right direction ( In fact, it's because the title is binary ....), Let's split the answer , One at a time t. Then think about the conditions that the left range and the right range of the answer will meet . It's obvious here , If for a machine , His ai * t <= bi, So it means that t Within time , The machine does not need to be charged . On the contrary, we need to focus ai * t - bi, Then look at t Whether the power bank can meet all the machines within the time . If meet , Then the answer is mid ~ r, Otherwise, it means that in l ~ mid.
code as follows :
#include <iostream>
using namespace std;
const int N = 100010;
int n, q;
double a[N], b[N], s;
bool cheak(double t)
{
double p = t * q, sum = 0;
for(int i = 1; i <= n; i ++ )
if(a[i] * t > b[i]) sum += a[i] * t - b[i];
return sum <= p;
}
int main()
{
scanf("%d%d", &n, &q);
for(int i = 1; i <= n; i ++ ) scanf("%lf%lf", &a[i], &b[i]), s += b[i];
if(q >= s) printf("-1\n");
else
{
double l = 0, r = 1e10;
while(r - l > 1e-5)
{
double mid = (l + r) / 2;
if(cheak(mid)) l = mid;
else r = mid;
}
printf("%.10lf", r);
}
return 0;
}边栏推荐
- pl/sql之集合-2
- The second lesson is the construction of development environment
- flink oracle cdc 读取数据一直为null,有大佬知道么
- 有限元学习知识点备案
- QT note 1
- If Yi Lijing spits about programmers
- MySQL 8.0 OCP (1z0-908) has a Chinese exam
- Cadence (x) wiring skills and precautions
- CIS 2020 - alternative skills against cloud WAF (pyn3rd)
- shell编程
猜你喜欢

NLP (natural language processing) natural language processing learning
![[time complexity, space complexity]](/img/f2/f82c7e0a6ab9f893023c2ddbac3431.png)
[time complexity, space complexity]

Winter vacation homework & Stamp cutting

File management file system based on C #

C#入门系列(三十一) -- 运算符重载

pl/sql之动态sql与异常

03异常处理,状态保持,请求钩子---04大型项目结构与蓝图

OA项目之我的会议(会议排座&送审)

Seq2seq and attention model learning notes

Nodejs2day(nodejs的模块化,npm下载包,模块加载机制)
随机推荐
Mysql8 dual master and dual slave +mycat2 read / write separation
Fluent custom popupmenubutton
Oracle 19C OCP 1z0-082 certification examination question bank (13-18)
Kotlin program control
[abstract base class inheritance, DOM, event - learning summary]
pl/sql之集合
Seq2seq and attention model learning notes
Deploy prometheus+grafana monitoring platform
Winter vacation homework & Stamp cutting
Does flinkcdc now support sqlserver instance name connection?
[untitled]
Shell programming
Logic of data warehouse zipper table
sklearn 机器学习基础(线性回归、欠拟合、过拟合、岭回归、模型加载保存)
Oracle 19C OCP certification examination software list
基于C#实现的文件管理文件系统
Arbitrum Nova release! Create a low-cost and high-speed dedicated chain in the game social field
Cadence (x) wiring skills and precautions
23.8 using the applicationrunner or commandlinerunner to implement applicationrunner and commandlinerunner
JS tool function Encyclopedia