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 Zhang_Jianlong at 2009-03-25 23:37:07 on Problem 2376
#include<stdio.h>

int main()
{
	long N,T,i,begin,end;
	scanf("%d%d",&N,&T);
	long *a=new long[T+1];
	for(i=0;i<=T;i++)
		a[i]=0;
	for(i=1;i<=N;i++)
	{
		scanf("%d%d",&begin,&end);
		if(end>a[begin])
			a[begin]=end;
	}
	long count=0,max=0,index;
	begin=1;
	end=0;
	while(end!=T)
	{
		++count;
		end=a[begin];
		max=a[begin];
		index=begin;
		for(i=end;i>begin&&end!=T;i--)
			if(a[i]>max)
			{
				max=a[i];
				index=i;
			}
		if(a[index]==end)
			break;
		begin=index;
		printf("end=%d\n",end);
	}
	if(end!=T)
		printf("%d\n",-1);
	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