标签:col include i++ pac http for problem clu div
题目大意:n件衣服,每件有ai水分。每分钟可自然风干1个水分,或者放入机器中风干k个水分。
问最少花多长时间,衣服全干。
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define N 100009 using namespace std; int n; int a[N]; int k,ans; bool ok(int x) { int js=0; for(int i=1;i<=n;i++) { if(a[i]<=x) continue; js=js+(a[i]-x+k-2)/(k-1); if(js>x) return false; } return true; } int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); scanf("%d",&k); sort(a+1,a+n+1); int L=1,R=a[n]; if(k==1) { cout<<a[n]<<endl; return 0; } while(L<=R) { int mid=(L+R)>>1; if(ok(mid)) { ans=mid; R=mid-1; }else L=mid+1; } cout<<ans<<endl; return 0; }
标签:col include i++ pac http for problem clu div
原文地址:https://www.cnblogs.com/zzyh/p/11980252.html