题目链接:http://codeforces.com/contest/801/problem/C

题意:给出一个充电器每秒钟充p个点,还有n个电器要同时使用a[i]表示第i个电器每秒钟用多少点,b[i]表示第i个

原来存了都少电。充电器可以无缝切换这充电,但是只能给一个充(同一时间)。最后问你最长可用多久,如果可以

无限时间的用的话,就输出-1。

题解:首先确定一下什么时候输出-1也就是可以无限充电的情况,就是p大于所有a的总和就行。

然后就是时间有限的情况。这里明确一个式子。

need*t=a[i]*t-b[i],(need表示每秒需要的时间,t表示时间)然后for一下1~n

need+=(a[i]-b[i]/t)

如果need<=p那么这个时间就是符合的。

然后就是枚举时间,枚举时间可以用二分,不妨设l=0,r=1e10,mid=(l+r)/2。然后就是二分的次数,由于精度要求是

1e-4所以二分50次左右就够了。

#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int M = 1e5 + 10;
double a[M] , b[M];
int main() {
int n;
double p;
scanf("%d%lf" , &n , &p);
double sum = 0;
for(int i = 0 ; i < n ; i++) {
scanf("%lf%lf" , &a[i] , &b[i]);
sum += a[i];
}
if(sum <= p) {
cout << -1 << endl;
}
else {
double l = 0 , r = 1e10;
double mid = (l + r) / 2;
for(int j = 1 ; j <= 50 ; j++) {
mid = (l + r) / 2;
double need = 0;
for(int i = 0 ; i < n ; i++) {
need += max(0.0 , 1.0 * a[i] - b[i] / mid);
}
if(need <= p) l = mid;
else r = mid;
}
printf("%.10lf\n" , l);
}
return 0;
}

Codeforces Round #409 C. Voltage Keepsake(二分+思维)的更多相关文章

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

  2. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) A B C D 暴力 水 二分 几何

    A. Vicious Keyboard time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  3. Codeforces Round#409/VK-Cup 2017 Round2

    来自FallDream的博客,未经允许,请勿转载,谢谢. 和ditoly组队打VK-Cup,起了个名字叫Vegetable Chicken(意思显然),然后昨天我做AB他切C 很不幸的是.....我写 ...

  4. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2) 题解【ABCDE】

    A. Vicious Keyboard 题意:给你一个字符串,里面只会包含VK,这两种字符,然后你可以改变一个字符,你要求VK这个字串出现的次数最多. 题解:数据范围很小,暴力枚举改变哪个字符,然后c ...

  5. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  6. Codeforces Round #404 (Div. 2) C 二分查找

    Codeforces Round #404 (Div. 2) 题意:对于 n and m (1 ≤ n, m ≤ 10^18)  找到 1) [n<= m] cout<<n; 2) ...

  7. [Educational Codeforces Round 63 ] D. Beautiful Array (思维+DP)

    Educational Codeforces Round 63 (Rated for Div. 2) D. Beautiful Array time limit per test 2 seconds ...

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

  9. Codeforces 801C Voltage Keepsake(二分枚举+浮点(模板))

    题目链接:http://codeforces.com/contest/801/problem/C 题目大意:给你一些电器以及他们的功率,还有一个功率一定的充电器可以给这些电器中的任意一个充电,并且不计 ...

随机推荐

  1. 【python-django后端开发】Redis缓存配置使用详细教程!!!

    官方查阅资料:https://django-redis-chs.readthedocs.io/zh_CN/latest/ 1. 安装django-redis扩展包 1.安装django-redis扩展 ...

  2. Dubbo里面线程池的拒绝策略

    Dubbo里面线程池的拒绝策略 public class AbortPolicyWithReport extends ThreadPoolExecutor.AbortPolicy { protecte ...

  3. .NET Core 3.0深入源码理解HttpClientFactory之实战

      写在前面 前面两篇文章透过源码角度,理解了HttpClientFactory的内部实现,当我们在项目中使用时,总会涉及以下几个问题: HttpClient超时处理以及重试机制 HttpClient ...

  4. 【原创】HashMap复习精讲

    引言 由于近期忙着搬家,又偷懒了几个礼拜! 其实我很早以前就想写一篇关于HashMap的面试专题.对于JAVA求职者来说,HashMap可谓是集合类的重中之重,甚至你在复习的时候,其他集合类都不用看, ...

  5. A solution to the never shortened to-do list

    I once told my younger sister my learning system, and the basic five doctrines of my methodology. Bu ...

  6. python3学习-logging模块

    1.logging模块的使用非常简单,引入模块就可以使用. import logging logging.debug('This is debug message') logging.info('Th ...

  7. node 删除和复制文件或文件夹

    [toc] 创建时间:2019-08-12 注意:在win10,v10.16.1 环境运行无问题 首先引入相关包(会在使用处具体说明): const fs = require('fs') const ...

  8. 常量Const

    常量Const YEAR = 2019 # 全部大写的变量名为常量 注释 给不能理解的写一个描述 便于理解 增强可读性 三种形式 单行(当行)注释:# 只注释一行 不能换行 注释的代码不执行 不使用 ...

  9. abp(net core)+easyui+efcore实现仓储管理系统——使用 WEBAPI实现CURD (十三)

    abp(net core)+easyui+efcore实现仓储管理系统目录 abp(net core)+easyui+efcore实现仓储管理系统——ABP总体介绍(一) abp(net core)+ ...

  10. 记几个 DOM 操作技巧

    使用 attributes 属性遍历元素特性 // 迭代元素的每一个特性,将它们构造成 name = value 的字符串形式 function outputAttributes (element) ...