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

请教诸大牛,为何一直TLE呢?

Posted by 20083331 at 2010-03-25 13:03:07 on Problem 2376
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAX=25005;

struct node
{
	int x;
	int y;
}data[MAX];

int cmp(node a,node b)
{
	if(a.x==b.x)
		return a.y>b.y;
	else
		return a.x<b.x;
}

int main()
{
	int N,T;
	scanf("%d%d",&N,&T);
	for(int i=0;i<N;i++)
		scanf("%d%d",&data[i].x,&data[i].y);
	sort(data,data+N,cmp);

	int loc=0;
	int index=0;
	int count=0;
	int max_right=0;
	bool flag=false;

	if(data[0].x!=1)
	{
		printf("-1\n");
		return 0;
	}

	while(loc<T && index<N)
	{
		int i;
		for(i=index;i<N;i++)
		{
			if(data[i].x<=loc+1)
			{
				if(data[i].y>max_right && data[i].y>loc)
				{
					flag=true;
		//			printf("%d %d\n",data[i].x,data[i].y);
					max_right=data[i].y;
				}
			}
			else
				break;
		}

		if(flag)
		{
			count++;
			loc=max_right;
			flag=false;
		}

		if(data[i].y<=loc)
			index++;
	}
	if(loc<T)
		printf("-1\n");
	else
		printf("%d\n",count);

	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