| ||||||||||
| 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 <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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator