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 |
顶In Reply To:谁能帮我看下到底是什么地方错了 谢谢 代码见内!!!!!! Posted by:yanhaofeng at 2007-07-22 09:48:22 > #include<stdio.h> > int m,n,a[1000010]; > int check(int mid) > { int nu=0,month=1,i,k; > for(i=1;i<=n;i++) > { k=nu+a[i]; > if(k>mid) > { month++;nu=a[i]; } > else{ nu+=a[i]; } > if(month>m)return -1; > > } > return month; > } > int main() > { int i,j,k,min,max,mid; > int nu,month; > while(1) > { scanf("%d%d",&n,&m); > min=-1; > for(i=1;i<=n;i++) > { scanf("%d",&a[i]); > if(min<a[i])min=a[i]; > } > max=10000;mid=0; > while(min<max-1) > { mid=(min+max)/2; > month=check(mid); > if(month==-1){min=mid;continue;} > if(month<=m)max=mid; > > } > month=check(min);k=check(max); > j=check(mid); > if(month==m)mid=min; > if(j==-1)mid=max; > printf("%d\n",mid);break; > } > } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator