88分#9TLE求调

P1843 奶牛晒衣服

这题建议用二分答案(答案具有单调性) 就是二分查找枚举答案 ``` #include <bits/stdc++.h> using namespace std; int n,a,b,x[500005]; bool check(int t) { int tot=0; //所有衣服弄干 意味着每件衣服都必须在时间t以内干掉 //设l(l>=0,l是整数)是第i件衣服使用的烘干机时长 //l*(a+b)+(t-l)*a>=x[i] //l>=(x[i]-t*a)/b //对于所有衣服tot(x)<= t //return 1; for(int i=1; i<=n; i++) { int l=(x[i]-t*a)/b; if(x[i]>=t*a) { if((x[i]-t*a)%b!=0) { l++; } tot+=l; } } return tot<=t ; } int main() { cin>>n>>a>>b; for(int i=1; i<=n; i++) { cin>>x[i]; } int l=1,r=5e5,sum=r; while(l<=r) { int mid=(l+r)/2; if(check(mid)) { sum=min(sum,mid); r=mid-1; } else { l=mid+1; } } cout<<sum; } ```
by LVFUyang1 @ 2024-01-29 17:32:46


啊忘记结帖了,我早二分ac了,不过还要谢谢你,已关
by qusia_MC @ 2024-01-31 18:04:16


可我觉得我这算法也对啊 @[LVFUyang1](/user/785296)
by qusia_MC @ 2024-01-31 18:06:03


|