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

WA得我伤心了啊,有人可以帮我看看吗?

Posted by liqi5277 at 2008-07-30 15:53:06 on Problem 2376
#include<stdio.h>
#include<iostream>
using namespace std;
typedef struct line
{
	int x;
	int y;
}line;
line a[25010];

int cmp(const void *a,const void *b)
{
	return  (*(line*)a).x-(*(line*)b).x;
}
int main()
{
	int n,t,i,tmp,na=0,count=0,flg,ty;
	scanf("%d %d",&n,&t);
	for(i=0;i<n;i++)
		scanf("%d %d",&a[i].x,&a[i].y);
	qsort(a,n,sizeof(a[0]),cmp);
	
	tmp=0;
	i=0;
	while(tmp<t&&i<=n)
	{
		flg=0;
		while(a[i].x<=tmp+1)
		{
			flg=1;
			if(a[i].y>ty)
				ty=a[i].y;
			i++;
		}
		count++;
		if(!flg)
		{
			na=1;
			break;
		}
		tmp=ty;
	
		
	}
	if(na)
	{
		printf("-1\n");
		return 0;
	}
	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