赤裸二分
#include<iostream> #include<cmath> using namespace std; const int N=300010; int n,m,rr; int c[N]; bool check(int mid) { int cot=0; for(int i=1; i<=m; i++) { int x=c[i]/mid; int y=c[i]%mid; if(y) cot+=x+1; else cot+=x; } return cot<=n; } int binary_search() { int l=1,r=rr; while(l<r) { int mid=(l+r)/2; if(check(mid)) r=mid; else l=mid+1; } return l; } int main() { scanf("%d %d",&n,&m); for(int i=1; i<=m; i++) { scanf("%d",&c[i]); rr=max(c[i],rr); } cout<<binary_search(); return 0; }
标签:二分,int,COCI2012,LJUBOMORA,P7585,include From: https://www.cnblogs.com/mantou20210331/p/17099333.html