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> #include<stdlib.h> int a[10000]; int m,n; int main() { int i,mid; int max=0; int min=0; int judge(int mid,int a[]); scanf("%d %d",&n,&m); for(i=1;i<=n;i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) max=max+a[i]; for(i=1;i<=n;i++) if(min<a[i]) min=a[i]; mid=(min+max)/2; while(min<max) { mid=(min+max)/2; if((judge(mid,a))==1) min=min+1; else max=max-1; } printf("%d",mid); system("pause"); return 0; } int judge(int mid,int a[]) { int i,sum=0; int group=1; for(i=1;i<=n;i++) { if(sum<=mid) sum=sum+a[i]; else { sum=a[i]; group++; } } if(group>m) return 1; else return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator