CodeForces 772A Voltage Keepsake
二分答案,验证。
二分到一个答案,比他小的时间都需要补充到这个时间,计算所需的量,然后和能提供的量进行比较。
#include <cstdio>
#include <cmath>
#include <set>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std; int n, p;
int a[],b[]; bool check(double x)
{
double sum = ;
double t = ;
for(int i=;i<=n;i++)
{
if(1.0*b[i]/a[i]>=x) continue;
sum = sum + (x-1.0*b[i]/a[i])*a[i];
} if(sum==) return ; if(sum<=x*p) return ;
return ;
} int main()
{
scanf("%d%d",&n,&p);
for(int i=;i<=n;i++)
{
scanf("%d%d",&a[i],&b[i]);
} double L = ,R = 100000.0;
R=R*R; double INF=R; double ans;
int t=;
while(t--)
{
double mid = (L+R)/; if(check(mid)) L=mid,ans=mid;
else R=mid;
} double eps = 1e-;
if(abs(ans-INF)<eps) printf("-1\n");
else printf("%f\n",ans); return ;
}
CodeForces 772A Voltage Keepsake的更多相关文章
- Codeforces 772A Voltage Keepsake - 二分答案
You have n devices that you want to use simultaneously. The i-th device uses ai units of power per s ...
- Codeforces 801C - Voltage Keepsake
C. Voltage Keepsake 题目链接:http://codeforces.com/problemset/problem/801/C time limit per test 2 second ...
- Codeforces 801C Voltage Keepsake(二分枚举+浮点(模板))
题目链接:http://codeforces.com/contest/801/problem/C 题目大意:给你一些电器以及他们的功率,还有一个功率一定的充电器可以给这些电器中的任意一个充电,并且不计 ...
- Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) C Voltage Keepsake
地址:http://codeforces.com/contest/801/problem/C 题目: C. Voltage Keepsake time limit per test 2 seconds ...
- Voltage Keepsake CodeForces - 801C (贪心 || 二分)
C. Voltage Keepsake time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces801C Voltage Keepsake 2017-04-19 00:26 109人阅读 评论(0) 收藏
C. Voltage Keepsake time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【codeforces 801C】Voltage Keepsake
[题目链接]:http://codeforces.com/contest/801/problem/C [题意] 有n个设备 你想同时使用 第i个设备每分钟消耗ai点电量,一开始有bi点电量 你有一个充 ...
- Codeforces Round #409 C. Voltage Keepsake(二分+思维)
题目链接:http://codeforces.com/contest/801/problem/C 题意:给出一个充电器每秒钟充p个点,还有n个电器要同时使用a[i]表示第i个电器每秒钟用多少点,b[i ...
- Voltage Keepsake CodeForces - 801C (思维+二分)
题目链接 这是一道很棒的二分题. 思路: 首先先思考什么情况下是可以无限的使用,即输出-1. 我们思考可知,如果每一秒内所有设备的用电量总和小于等于充电器每秒可以充的电,那么这一群设备就可以无限使用. ...
随机推荐
- K8S Link
https://www.cnblogs.com/linuxk/p/9783510.html https://www.cnblogs.com/fengzhihai/p/9851470.html
- [DeeplearningAI笔记]序列模型2.8 GloVe词向量
5.2自然语言处理 觉得有用的话,欢迎一起讨论相互学习~Follow Me 2.8 GloVe word vectors GloVe词向量 Pennington J, Socher R, Mannin ...
- [LeetCode] 28. Implement strStr() ☆
Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...
- 多例模式,保证实例的唯一性,仅适用于form窗体
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...
- CF544 C 背包 DP
n个人写m行代码,第i人写一行代码有a[i]个bug,问总bug数不超过b的不同方案数. 其实就是个背包,dp[i][j][k]代表前i个人写了j行代码用了k个bug限度,然后随便转移一下就好了 /* ...
- 课程设计——利用信号量实现生产者-消费者问题(java)
package cn.Douzi.ProductConsume; import java.util.LinkedList; import java.util.Queue; import java.ut ...
- 【BZOJ】2049: [Sdoi2008]Cave 洞穴勘测 LCT
[题意]给定n个点和m个操作,每次操作:1.连接2个点.2.断开2个点.3.查询2个点是否连通.m<=2*10^5. [算法]Link-Cut Tree [题解]LCT模板题,Link,Cut, ...
- 【CodeForces】913 C. Party Lemonade
[题目]C. Party Lemonade [题意]给定n个物品,第i个物品重量为2^(i-1)价值为ci,每个物品可以无限取,求取总重量>=L的最小代价.1<=30<=n,1< ...
- How to reset XiaoMi bluetooth headphone Youth edition.
To reset the speaker 1. Long press the phone call button to shut off the speaker 2. Connect the char ...
- 【洛谷 P3191】 [HNOI2007]紧急疏散EVACUATE(二分答案,最大流)
题目链接 sb错误调了3hour+.. bfs预处理出每个\(.\)到每个\(D\)的最短距离. 二分时间\(t\),把每个\(D\)拆成\(t\)个点,这\(t\)个点两两连边,流量\(INF\)表 ...