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 zhaoguanqin at 2011-06-30 17:46:25 on Problem 1065 and last updated at 2011-06-30 17:48:29
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct ss{
	int x,y,z;
};
int cmp(ss w,ss t)
{
	if(w.x==t.x)return w.y<t.y;
	else return w.x<t.x;
}
int main()
{
	int i,n,sum,k,flag,j;
	ss a[5005];
	scanf("%d",&k);
	while (k--)
	{
		sum=0;
		scanf("%d",&n);
		for (i=0;i<n;i++)
		{
			scanf("%d%d",&a[i].x,&a[i].y);
			a[i].z=0;
		}
		sort(a,a+n,cmp);
		flag=n;
		for(j=0;j<=n-1;j++)
		{
			if(a[j].z==0)	
			{
				sum++;
				int ww=j;
			for (i=ww+1;i<=n-1;i++)
			{	
				if(a[i].z==0&&a[i].y>=a[ww].y)
				{
					a[i].z=-1;
					ww=i;
				}
			}
			}
        }
		printf("%d\n",sum);
	}
	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