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 chenxuan123456789 at 2012-09-15 22:49:56 on Problem 2376
#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
	int s;
	int e;
}Node;
Node p[1000010];
int cmp(const void *_a,const void *_b)
{
	Node *a=(Node*)_a;
	Node *b=(Node*)_b;
	if(a->s==b->s)
		return b->e-a->e;
	return a->s-b->s;
}
int main()
{
	int n,t,i,j,f,c,mark,mx,k;
	while(scanf("%d %d",&n,&t)!=EOF)
	{
		for(i=0;i<n;i++)
		scanf("%d %d",&p[i].s,&p[i].e);
		qsort(p,n,sizeof(p[0]),cmp);
		if(p[0].s!=1)
		{
			printf("-1\n");
            continue;
		}
		if(p[0].s==1&&p[0].e==t)
		{
			printf("1\n");
			continue;
		}
		c=1;
		f=0;
		for(i=0;i<n;)
		{
			mark=0;
			mx=p[i].e;
			for(j=i+1;j<n;j++)
			if(p[j].s>=p[i].s&&p[j].s<=p[i].e+1)
			{
				if(p[j].e>mx)
				{
					mx=p[j].e;
					k=j;
					mark=1;
				}
			}
			if(mark)
			{
				i=k;
				c++;
			}
			else
				break;
			if(p[i].e==t)
			{
				f=1;
				break;
			}
		}
		if(f)
			printf("%d\n",c);
		else
			printf("-1\n");
	}
	return 1;
}


		
			

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