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 fengjinming at 2007-07-23 11:09:33
#include <iostream>
using namespace std;
bool ok(long int k,long int num[],long int m,long int n)
{
	long int sum,i,count;
	count=1;
    sum=0;
	i=0;
	while(i<m)
	{
		sum+=num[i++];
        if(sum>k-num[i])
		{
			count++;
			sum=0;
		}
	}
	if(count<=n)
		return true;
	else 
		return false;
}
void find(long int left,long int right,long int num[],long int m,long int n,long int &ex)
{
	long int mid;
	if(left<right)
	{
		mid=(left+right)/2;
		if(ok(mid,num,m,n))
		   find(left,mid,num,m,n,ex);
		else
			find(mid+1,right,num,m,n,ex);
	}
	else
		ex=left;
}
	

int main()
{
	long int m,n,i,ex,max,sum;
	cin>>m>>n;
	max=0;
	sum=0;
	long int *num=new long int[m];
	for(i=0;i<m;i++)
	{
		cin>>num[i];
		sum+=num[i];
		if(num[i]>max)
			max=num[i];
	}
	find(max,sum,num,m,n,ex);
	cout<<ex<<endl;
	return 0;
}


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