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

同样的代码,有时候是ac,有时候wa,什么情况?

Posted by hansechang at 2010-07-22 11:15:44 on Problem 2376
#include<stdio.h>
#include<algorithm>
using namespace std;
struct node{
	int start,end;
}cow[25010];
bool cmp(node x,node y){
	if(x.start<=y.start)
		return true;
	else
		return false;
}
int main(){
	int n,t,i,count,tail,p,m;
	scanf("%d%d",&n,&t);
	for(i=0;i<n;i++)
		scanf("%d%d",&cow[i].start,&cow[i].end);
	sort(cow,cow+n,cmp);
	count=tail=p=0;
	while(tail!=t){
		m=tail;
		while(cow[p].start<=tail+1){
			if(cow[p].end>m)
				m=cow[p].end;
			p++;
		}
		if(m==tail)
			break;
		tail=m;
		count++;
	}
	if(tail!=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