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 |
精度啊 !!!挖了n次之后终于AC了 以下是代码可以看出对精度要求是多么苛刻还是对精度的了解不够深啊 真难控制 #include <iostream> #include <algorithm> using namespace std; double t; __int64 num[100000],start,mid,end;__int64 sum,n,k; int main(){ __int64 i; while(scanf("%I64d%I64d",&n,&k)!=-1){ for(i=0;i<n;i++){ scanf("%lf",&t); t*=100; num[i]=int(t); sum+=num[i]; } if(sum<k){printf("0.00\n");continue;} sort(num,num+n); start=1;end=num[0]; while(start+1<end){ sum=0; mid=(start+end)/2; for(i=0;i<n;i++)sum+=num[i]/mid; if(sum<k)end=mid; if(sum>=k)start=mid; } sum=0; for(i=0;i<n;i++)sum+=num[i]/end; if(sum>=k)printf("%.2lf\n",end*0.01); else printf("%.2lf\n",start*0.01); } return 0; } /* 4 11 8.02 7.43 4.57 5.39 */ Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator