[Luogu1843]奶牛晒衣服

题目大意:
  你要晒n件衣服,第i件衣服有w[i]滴水,
  每件衣服每秒钟会自然风干a滴水,将这件衣服放入烘干机中每秒钟会烘干a+b滴水。
  一秒钟不可以拆开,问晒干所有的衣服至少要多少时间?

思路:
  二分答案判断可行性。

 1 #include<cstdio>
 2 #include<cctype>
 3 inline int getint() {
 4     register char ch;
 5     while(!isdigit(ch=getchar()));
 6     register int x=ch^'0';
 7     while(isdigit(ch=getchar())) x=(((x<<2)+x)<<1)+(ch^'0');
 8     return x;
 9 }
10 const int N=500000;
11 int w[N],n,a,b;
12 inline bool check(const int &m) {
13     int tmp=0;
14     for(register int i=0;i<n;i++) {
15         if(w[i]>m*a) tmp+=((w[i]-m*a)-1)/b+1;
16     }
17     return tmp<=m;
18 }
19 int main() {
20     n=getint(),a=getint(),b=getint();
21     for(register int i=0;i<n;i++) {
22         w[i]=getint();
23     }
24     int l=0,r=N;
25     while(l<r) {
26         const int mid=(l+r)>>1;
27         if(check(mid)) {
28             r=mid;
29         } else {
30             l=mid+1;
31         }
32     }
33     printf("%d
",r);
34     return 0;
35 }
原文地址:https://www.cnblogs.com/skylee03/p/7756463.html