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

sos!一直TLE,不知道是我理解错了,还是什么```怎么想这题也不会是改TLE的题啊!!大牛们帮帮忙

Posted by cangratul at 2007-02-06 20:58:15 on Problem 2782
#include <stdio.h>
#include <algorithm>
short a[100000];
bool cmp(short &x,short &y)
{
	return x>=y;
}
void main()
{
	int n,max,min,mid,i,z;
	short l;
	scanf("%d %hd",&n,&l);
	for(i=0;i<n;i++) scanf("%hd",&a[i]);
	std::sort(a,a+n,cmp);
	if(n%2!=0) min=(n>>1)+1;
	else min=n>>1;
	max=n;
	while(min<=max)
	{
		mid=(max+min)>>1;
		z=(mid<<1)-1;
		for(i=mid;i<n;i++)
		{
			if((a[i]+a[z-i])>l)
			{
				min=mid+1;
				goto next;
			}
		}
		max=mid-1;
next:   ;
	}
	max++;
	printf("%d\n",max);
}

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