当前位置: 首页 > news >正文

POJ 3104 Drying 二分

题目链接:http://poj.org/problem?id=3104

题目大意:有N件衣服需要晒干,但是晒干的话是一秒蒸发一滴水,而你买个了烘干机,一秒钟可以烘干K滴水。现在给你衣服里面的含水量ai滴水以及K问最少多长时间能干。烘干机一秒只能放一件衣服。

解题思路:二分时间+check。主要问题在于check。由于烘干的时候每秒K滴水,而晒干每秒一滴水,那么我们可以认为烘干时每秒K-1滴水,任意时刻(无论在烘干与否)每秒都会自然蒸发一滴水。

那么整个过程就很清晰了:对于一个时间T,将每个ai减去T,如果ai>0,那么就计算需要多长时间烘干(K-1的烘干机),如果计算结果>T则无法完成。

注意在计算时一旦中间结果>T就返回, K = 1特判一下不然RE。。。

代码:

 1 const int inf = 0x3f3f3f3f;
 2 const int maxn = 1e5 + 5;
 3 int n, k;
 4 ll a[maxn];
 5 
 6 int check(ll x){
 7     ll ans = 0;
 8     for(int i = 1; i <= n; i++){
 9         int tmp = a[i] - x;
10         if(tmp > 0) {
11             ll u = tmp / (k - 1);
12             ll v = tmp % (k - 1);
13             if(v > 0) u++;
14             ans += u;
15         }
16         if(ans > x) return -1;
17     }
18     return 1;
19 }
20 
21 void solve(){
22     
23     ll l = 1, r = 1e9;
24     while(l < r){
25         ll mid = (l + r) >> 1;
26         if(check(mid) == -1) l = mid + 1;
27         else r = mid;
28     }
29     printf("%lld\n", l);
30 }
31 int main(){
32     scanf("%d", &n);
33     ll maxa = 0;
34     for(int i = 1; i <= n; i++) {
35         scanf("%lld", &a[i]);
36         maxa = max(a[i], maxa);
37     }
38     scanf("%d", &k);
39     if(k == 1){
40         printf("%d", maxa);
41         return 0;
42     }
43     solve();
44 }

题目:

Drying
Time Limit: 2000MS Memory Limit: 65536K
Total Submissions: 17856 Accepted: 4488

Description

It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She is not afraid of this boring process. Jane has decided to use a radiator to make drying faster. But the radiator is small, so it can hold only one thing at a time.

Jane wants to perform drying in the minimal possible time. She asked you to write a program that will calculate the minimal time for a given set of clothes.

There are n clothes Jane has just washed. Each of them took ai water during washing. Every minute the amount of water contained in each thing decreases by one (of course, only if the thing is not completely dry yet). When amount of water contained becomes zero the cloth becomes dry and is ready to be packed.

Every minute Jane can select one thing to dry on the radiator. The radiator is very hot, so the amount of water in this thing decreases by k this minute (but not less than zero — if the thing contains less than k water, the resulting amount of water will be zero).

The task is to minimize the total time of drying by means of using the radiator effectively. The drying process ends when all the clothes are dry.

Input

The first line contains a single integer n (1 ≤ n ≤ 100 000). The second line contains ai separated by spaces (1 ≤ ai ≤ 109). The third line contains k (1 ≤ k ≤ 109).

Output

Output a single integer — the minimal possible number of minutes required to dry all clothes.

Sample Input

sample input #1
3
2 3 9
5

sample input #2
3
2 3 6
5

Sample Output

sample output #1
3

sample output #2

转载于:https://www.cnblogs.com/bolderic/p/7372521.html

相关文章:

  • hihocoder-1546-集合计数
  • JTemplates + $.Ajax
  • 面向对象编程思想-命令模式
  • C#自定义事件模拟风吹草摇摆
  • 仿真反射详解(二)
  • alwayson01-搭建域环境
  • freemark基础知识
  • avaweb(三十二)——JDBC学习入门
  • 希尔排序之C++实现(初级版)
  • 在linux中,如何增加、修改、删除、暂停和冻结用户名
  • 深入理解Java内存模型——volatile
  • js面试中长见的算法题(转载)
  • Mybatis避免出现语法错
  • 94)图片验证码
  • css的存在形式及优先级
  • 【前端学习】-粗谈选择器
  • C++回声服务器_9-epoll边缘触发模式版本服务器
  • CSS 三角实现
  • ES10 特性的完整指南
  • HTTP 简介
  • JavaScript 基本功--面试宝典
  • JavaScript 基础知识 - 入门篇(一)
  • mysql_config not found
  • PAT A1050
  • Spring Cloud中负载均衡器概览
  • 闭包--闭包作用之保存(一)
  • 观察者模式实现非直接耦合
  • 基于HAProxy的高性能缓存服务器nuster
  • 前端面试之CSS3新特性
  • 如何打造100亿SDK累计覆盖量的大数据系统
  • 什么是Javascript函数节流?
  • 听说你叫Java(二)–Servlet请求
  • 详解NodeJs流之一
  • 携程小程序初体验
  • 用Visual Studio开发以太坊智能合约
  • 阿里云移动端播放器高级功能介绍
  • 格斗健身潮牌24KiCK获近千万Pre-A轮融资,用户留存高达9个月 ...
  • 微龛半导体获数千万Pre-A轮融资,投资方为国中创投 ...
  • ​ 全球云科技基础设施:亚马逊云科技的海外服务器网络如何演进
  • ​​​​​​​​​​​​​​Γ函数
  • ​io --- 处理流的核心工具​
  • #我与Java虚拟机的故事#连载18:JAVA成长之路
  • (翻译)Entity Framework技巧系列之七 - Tip 26 – 28
  • (分享)一个图片添加水印的小demo的页面,可自定义样式
  • (附源码)spring boot网络空间安全实验教学示范中心网站 毕业设计 111454
  • (没学懂,待填坑)【动态规划】数位动态规划
  • (七)c52学习之旅-中断
  • (原創) 人會胖會瘦,都是自我要求的結果 (日記)
  • (原創) 如何將struct塞進vector? (C/C++) (STL)
  • (轉)JSON.stringify 语法实例讲解
  • .mat 文件的加载与创建 矩阵变图像? ∈ Matlab 使用笔记
  • .net 4.0 A potentially dangerous Request.Form value was detected from the client 的解决方案
  • .net mvc actionresult 返回字符串_.NET架构师知识普及
  • .NET 使用 ILRepack 合并多个程序集(替代 ILMerge),避免引入额外的依赖
  • .NET 线程 Thread 进程 Process、线程池 pool、Invoke、begininvoke、异步回调