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 |
Re:为什么我的二分不行啊,大家帮我看看好吗?In Reply To:为什么我的二分不行啊,大家帮我看看好吗? Posted by:KangBox at 2007-09-19 00:40:00 > #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