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 |
我也是用二分法做的 ,怎么就不对了?我不知道是我判断的方法不对,,还是其他什么问题,哪位帮忙指点一下啊,代码写的很简单的 #include <stdio.h> int main() { long m,n,i,k; double a[100000],min,max,mid,sum; while(EOF!=scanf("%d%d",&m,&n)) { min=1;max=0; for(i=0;i<m;i++) { scanf("%lf",a+i); if(min<a[i])min=a[i]; max+=a[i]; } while(max-min>0.1) { mid=(max+min)/2; k=0; sum=0; for(i=0;i<m;i++) { sum+=a[i]; if(sum>mid) { sum=a[i]; k++; } else if(sum==mid) { sum=0; k++; } } if(k<=n)max=mid; else min=mid; } printf("%.0lf\n",mid); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator