Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么我的二分不行啊,大家帮我看看好吗?

Posted by KangBox at 2007-09-19 00:40:00 on Problem 3273
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator