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 |
一定要用floor函数,不然是4舍5入啊.#include<iostream> #include<stdio.h> #include<math.h> #define N 10000+7 using namespace std; int n,k; double a[N]; bool can(double x) { int cnt=0; for(int i=0;i<n;i++) { cnt+=int(a[i]/x); } if(cnt<k)return false; else return true; } int main() { freopen("/home/zlq/QTACMING/in","r",stdin); while(scanf("%d%d",&n,&k)!=EOF) { double m=-1; for(int i=0;i<n;i++) { scanf("%lf",&a[i]); if(a[i]>m){m=a[i];} } double l=0,r=m,mid; int cnt=0; while(r-l>1e-4) { mid=(l+r)/2; if(can(mid)) { l=mid; } else { r=mid; } cnt++; } printf("%.2f\n",floor(l*100)/100);//如果不加floor函数是四舍五入 } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator