您的位置:首页 > 其它

poj1828

2011-10-17 20:44 295 查看
找动态规划的题,却找到这道,动态规划该怎么做不知道,只会结构体二级排序。。。

#include <iostream>
#include <algorithm>
using namespace std;

#define N 50002

struct Position
{
	int x, y;
} monkey
;

bool compare(const Position &a, const Position &b)
{
	if(a.x != b.x)
		return a.x > b.x;
	else 
		return a.y > b.y;
}

int main()
{
	int n, i, cnt, tmp;
	
	while(scanf("%d", &n) && n)
	{
		for(i = 0; i < n; i++)
			scanf("%d%d", &monkey[i].x, &monkey[i].y);
		sort(monkey, monkey+n, compare);
		cnt = 1;
		tmp = monkey[0].y;
		for(i = 1; i < n; i++){
			if(monkey[i].y > tmp){
				cnt++;
				tmp = monkey[i].y;
			}
		}
		printf("%d\n", cnt);
	}
	return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: