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

why?? wa!!我用的 是贪心,请高手指教!TOJ可以AC的!

Posted by 407007351 at 2007-09-06 21:49:41 on Problem 1769
#include<iostream>
#include<algorithm>
using namespace std;
struct M
{
	int l,r;
}a[500005];
int n,m;
void set()
{
	for(int i=0;i<m;++i)
		scanf("%d%d",&a[i].l,&a[i].r);
}
inline bool cmp(M x,M y) 
{ 
	return x.l < y.l ;
} 
int main()
{
//	freopen("a.txt","r",stdin);
	while(scanf("%d%d",&n,&m),n&&m)
	{
		set();
		sort(a,a+m,cmp);
		int l=1,tag=0,maxx=0;
		for(int i=0;i<m;++i)
		{
			if(a[i].l<=l)
			{
				if(maxx<a[i].r)  maxx=a[i].r;
			}
			else
			{
				l=maxx;
				tag++;
				if(l>=n) break;
				i--;
			}
		}
		if(l<n)tag++;
		printf("%d\n",tag);
	}
	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