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 |
哥用double过了。。。//注意: 因为是用二分,所以left应该在标准值左边,可能会出现 x.999999这种情况 ,而right 就不会了。 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> const double limit = 1e-5; using namespace std; double all[10001]; bool num(double M,int N,int K){ int res=0; for(int i=0;i<N;i++){ res+=(all[i]/M); if(res>=K) return true; } return false; } int main(){ //freopen("E:\\Desktop\\in.txt","r",stdin); int N,K; while(scanf("%d%d",&N,&K)!=EOF){ double left,right,mid; double max_len=0; double tmp; for(int i=0;i<N;i++){ scanf("%lf",&all[i]); max_len=max(max_len,all[i]); } right=max_len; left=0;//配合最后的-1 为了处理为0.00 的情况 while(right-left>limit){ mid=(left+right)/2; if(num(mid,N,K)){ left=mid; } else{ right=mid; } } if((int)(right*1000)%10>=5) right-=0.005;//因为要用浮点数输出 所以 如果是 0.005 的话会输出0.01!!!!!!一定要注意 printf("%.2lf\n",(double)right); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator