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 days[100000]; int N,M; int check(int money){ int cnt, i, s; for( s = cnt = i = 0; i < N; i++) if( s + days[i] <= money ) s += days[i]; else cnt++ , s = days[i]; if( ++cnt <= M ) return 1; else return 0; } main(){ int check(int),low,high,mid,i; scanf("%d%d",&N,&M); for( low = i = 0; i < N; i++ ){ scanf("%d",days + i); if( days[i] > low ) low = days[i]; } high = 10000; while( low < high ){ mid = ( low + high ) / 2; if( check(mid) ) high = mid; else low = mid + 1; } printf("%d\n",high); } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator