博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 3104 Drying 二分
阅读量:5012 次
发布时间:2019-06-12

本文共 2891 字,大约阅读时间需要 9 分钟。

题目链接

题目大意:有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 #132 3 95sample input #232 3 65

Sample Output

sample output #13sample output #2

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

你可能感兴趣的文章
sed 常用操作纪实
查看>>
C++复习:对C的拓展
查看>>
校外实习报告(九)
查看>>
android之android.intent.category.DEFAULT的用途和使用
查看>>
CAGradientLayer 透明渐变注意地方(原创)
查看>>
织梦DEDE多选项筛选_联动筛选功能的实现_二次开发
查看>>
iOS关于RunLoop和Timer
查看>>
SQL处理层次型数据的策略对比:Adjacency list vs. nested sets: MySQL【转载】
查看>>
已存在同名的数据库,或指定的文件无法打开或位于 UNC 共享目录中。
查看>>
MySQL的随机数函数rand()的使用技巧
查看>>
thymeleaf+bootstrap,onclick传参实现模态框中遇到的错误
查看>>
python字符串实战
查看>>
wyh的物品(二分)
查看>>
12: xlrd 处理Excel文件
查看>>
综合练习:词频统计
查看>>
中文url编码乱码问题归纳整理一
查看>>
Cesium应用篇:3控件(3)SelectionIndicator& InfoBox
查看>>
58. Length of Last Word(js)
查看>>
前端面试题汇总(持续更新...)
查看>>
如何成为F1车手?
查看>>