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 Belldandy at 2013-10-17 18:34:40 on Problem 2376
In Reply To:最简单的代码!!!信不信由你!下面大牛提供的测试数据很给力!在这感谢大牛了! Posted by:chenxuan123456789 at 2012-09-15 22:49:56
#include <stdio.h>
#include <stdlib.h>
struct cows
{
	int start;
	int end;
}cow[25001];

int cmp(void const *a,void const *b)
{
	return ((struct cows *)a)->start-((struct cows *)b)->start;
}

int main()
{
	int N=0,T=0;
	int now=0,i=0,count=0,max=0;
	char flag=0;
	while(scanf("%d%d",&N,&T)!=EOF)
	{
		for(i=0;i<N;++i)
		{
			scanf("%d%d",&cow[i].start,&cow[i].end);
		}

		qsort(cow,N,sizeof(struct cows),cmp);
		for(i=0;i<N&&now<T;++count)
		{
			flag=0;
			while(i<N&&cow[i].start<=now+1)
			{
				if(cow[i].end>max)
				{
					max=cow[i].end;
					flag=1;
				}
				++i;
			}
			if(!flag)
			{
				break;
			}
			else
			{
				now=max;
			}
		}
		if(now<T)
		{
			puts("-1");
		}
		else
		{
			printf("%d\n",count);
		}
	}
}

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