| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
二分int,贴个代码#include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn = 10005; int n,k; double data[maxn]; bool ke(int x) { double div = x/1000.0; int cnt = 0; for(int i=1;i<=n;++i) { cnt +=(int)(data[i]/div); if(cnt>=k) return 1; } return 0; } int main() { while(scanf("%d%d",&n,&k)!=EOF) { int l = 1,r = 0,res=0; for(int i=1;i<=n;++i) { scanf("%lf",data+i); r = max(r,(int)(data[i]*1000)); } while(r>=l) { int m = (l+r)>>1; if(ke(m)) { l = m + 1; res = m; } else { r = m - 1; } } res -= res%10; printf("%.2lf\n",res/1000.0); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator