# POJ 1828 Monkeys' Pride（水~）

Description

Input

Output

Sample Input
3
2 1
1 2
3 3
3
0 1
1 0
0 0
4
0 0
1 0
0 1
1 1
0
Sample Output
1
2
1
Solution

Code

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF (1<<29)
#define maxn 100000
struct node
{
int x,y;
}num[maxn];
int n;
int cmp(node a,node b)
{
if(a.x==b.x)
return a.y<b.y;
return a.x<b.x;
}
int main()
{
while(scanf("%d",&n),n)
{
for(int i=0;i<n;i++)
scanf("%d%d",&num[i].x,&num[i].y);
sort(num,num+n,cmp);//对坐标点排序
int ans=1;
int xx=num[n-1].x;//从右向左
int yy=num[n-1].y;
for(int i=n-2;i>=0;i--)
{
if(num[i].x==xx)//遇到横坐标相同的点则跳过
continue;
else if(num[i].y>yy)//遇到比之前y值大的y值则更新,点数加一
{
xx=num[i].x;
yy=num[i].y;
ans++;
}
}
printf("%d\n",ans);
}
return 0;
}

#### poj1828-Monkeys' Pride

2011-08-15 23:53:51

#### poj 1828:Monkeys' Pride

2014-06-28 10:37:44

#### POJ 1828 Monkeys' Pride

2014-06-06 21:40:04

#### poj 1828 Monkeys' Pride

2013-10-04 12:35:54

#### POJ 1828 Monkeys' Pride 笔记

2017-06-22 22:30:09

#### poj 1828 Monkeys' Pride 模拟

2013-05-07 09:38:17

#### POJ 1828 MONKEYS’ PRIDE(DP)+POJ 2726

2011-08-20 19:09:40

#### acm pku 上第1828题，用qsort 排序，c语言版的程序，内附详细注释

2009年07月29日 941B 下载

#### POJ 1828 Monkeys' Prid

2014-03-12 18:31:42

#### POJ 1828 Monkeys' Pride (易 TLE 题目) -- from lanshui_Yang

2012-08-13 19:47:11