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. 我们思考可知,如果每一秒内所有设备的用电量总和小于等于充电器每秒可以充的电,那么这一群设备就可以无限使用. ...
随机推荐
- ubuntu系统安装mysql二进制压缩包(tar.gz)以及navicat远程连接服务器(linux系统)
一.ubuntu安装mysql5.6二进制压缩包(tar.gz) 准备 0. 获取 mysql-5.5.15-linux2.6-i686.tar.gz 二进制安装文件 mysql 官网下载页面选择 L ...
- 分块+二分 BZOJ 3343
3343: 教主的魔法 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1312 Solved: 585[Submit][Status][Discus ...
- Disruptor的使用
..................2015年的第一天................... 本文代码托管在 https://github.com/hupengcool/disruptor-start ...
- 浮动&定位
本文地址:http://www.cnblogs.com/veinyin/p/7606652.html 浮动和定位能够让我们把一些元素放到理想的位置,当然,相比之下 float 只能浮动到左边或右边, ...
- 【leetcode 简单】第二十题 合并两个有序数组
给定两个有序整数数组 nums1 和 nums2,将 nums2 合并到 nums1 中,使得 num1 成为一个有序数组. 说明: 初始化 nums1 和 nums2 的元素数量分别为 m 和 n. ...
- 可怕的npm蠕虫
https://hackernoon.com/im-harvesting-credit-card-numbers-and-passwords-from-your-site-here-s-how-9a8 ...
- [Gym-100625J] 搜索
题目链接:https://cn.vjudge.net/problem/Gym-100625J 具体思路:首先,具体思路是两个人一起走到一个点,然后两个人按照同样的道路走出去,听了别人的思路,还有一种特 ...
- appium===常用方法介绍,元素定位
https://testerhome.com/topics/3711 元素定位方法: find_element_by_android_uiautomator ,使用uiautomator定位,后面参数 ...
- 手机页面或是APP中减少使用setTimeout和setInterval,因为他们会导致页面卡顿
1.setTimeout致使页面的卡顿或是不流畅,打乱模块的生命周期 ,还有setTimeout其实是很难调试的. 当一个页面有众多js代码的时候,setTimeout就是导致页面的卡顿. var s ...
- docker简单介绍(资料收集总结)
[前言] 首先,感谢我的leader总是会问我很多技术的基本资料,让我这个本来对于各种技术只知道操作命令不关注理论知识的人,开始重视理论资料. 关于docker的操作步骤等等,都是之前学习的,现在补上 ...