| ||||||||||
| 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;
#define max(a,b) (((a) > (b)) ? (a) : (b))
int N;
__int64 M;
__int64 K;
__int64 leftLength[100000];
bool tryRun(__int64 t)
{
if (t==0)
return false;
int i;
__int64 tmp=0,j=M*t;
for(i=0;i<N;i++)
{
if (leftLength[i]-t<=0)
continue;
if (K == 1)
return false;
if ((leftLength[i]-t)%(K-1)==0)
tmp=(leftLength[i]-t)/(K-1);
else
tmp=(leftLength[i]-t)/(K-1)+1;
if (tmp>t || tmp>j)
return false;
j-=tmp;
}
return true;
}
int main()
{
int tc;
int i;
__int64 max_length;
__int64 low,high,mid;
scanf("%d",&tc);
while(tc--)
{
scanf("%d",&N);
max_length = 1;
for(i=0;i<N;i++)
{
scanf("%I64d",&leftLength[i]);
max_length = max(max_length,leftLength[i]);
}
scanf("%I64d%I64d",&M,&K);
low = 1;
high = max_length;
while(low<=high){
mid = (low + high) / 2;
if (tryRun(mid)){
if (!tryRun(mid-1))
{
printf("%I64d\n",mid);
break;
}
high = mid - 1;
}else{
low = mid + 1;
}
}
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator