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 yyfiby at 2007-05-10 10:50:24 on Problem 3232
#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:
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