POJ 2897 Monkeys' Pride 解题报告

Description

Background 
There are a lot of monkeys in a mountain. Every one wants to be the monkey king. They keep arguing with each other about that for many years. It is your task to help them solve this problem.

Problem 
Monkeys live in different places of the mountain. Let a point (x, y) in the X-Y plane denote the location where a monkey lives. There are no two monkeys living at the same point. If a monkey lives at the point (x0, y0), he can be the king only if there is no monkey living at such point (x, y) that x>=x0 and y>=y0. For example, there are three monkeys in the mountain: (2, 1), (1, 2), (3, 3). Only the monkey that lives at the point (3,3) can be the king. In most cases, there are a lot of possible kings. Your task is to find out all of them.

Input

The input consists of several test cases. In the first line of each test case, there are one positive integers N (1<=N<=50000), indicating the number of monkeys in the mountain. Then there are N pairs of integers in the following N lines indicating the locations of N monkeys, one pair per line. Two integers are separated by one blank. In a point (x, y), the values of x and y both lie in the range of signed 32-bit integer. The test case starting with one zero is the final test case and has no output.

Output

For each test case, print your answer, the total number of the monkeys that can be possible the king, in one line without any redundant spaces.

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

题目大意:求猴王的坐标。。。什么猴王的坐标不能同时被其他猴子超过。,。问有多少个猴王。。。解题思路:按X排序,然后用两个变量分别记录X和Y。。然后向下循环。。。。

 1 #include<stdio.h>
 2 #include<algorithm>
 3 using namespace std;
 4 struct monkey{
 5     int x;
 6     int y;
 7 }a[99999];
 8 bool com(monkey a,monkey b)
 9 {
10     if(a.x==b.x)
11         return a.y<b.y;
12     return a.x<b.x;
13 }
14 int main()
15 {
16     int n;
17     while(scanf("%d",&n)!=EOF)
18     {
19         if(n==0)break;
20         int i;
21         for(i=0;i<n;i++)
22         {
23             scanf("%d %d",&a[i].x,&a[i].y);
24         }
25         sort(a,a+n,com);
26         int X,Y,sum=1;
27         X=a[n-1].x;
28         Y=a[n-1].y;
29         for(i=n-1;i>=0;i--)
30         {
31             if(a[i].x==X)
32                 continue;
33             else
34             {
35                 if(a[i].y>Y)
36                 {
37                     Y=a[i].y;
38                     sum++;
39                 }
40             }
41         }
42         printf("%d\n",sum);
43     }
44     return 0;
45 }


POJ 2897 Monkeys' Pride 解题报告

时间: 2024-08-12 21:17:38

POJ 2897 Monkeys' Pride 解题报告的相关文章

poj 3020 Antenna Placement 解题报告

题目链接:http://poj.org/problem?id=3020 题目意思:首先,请忽略那幅有可能误导他人成分的截图(可能我悟性差,反正有一点点误导我了). 给出一幅 h * w 的图,  “ * ” 表示 point of interest,“ o ” 忽略之.你可以对 " * " (假设这个 “* ”的坐标是 (i, j))画圈,每个圈只能把它四周的某一个点括住(或者是上面(i-1, j) or 下面(i+1, j) or 左边(i, j-1)  or 右边(i, j+1))

poj 1789 Truck History 解题报告

题目链接:http://poj.org/problem?id=1789 题目意思:给出 N 行,每行7个字符你,统计所有的 行 与 行 之间的差值(就是相同位置下字母不相同),一个位置不相同就为1,依次累加.问最终的差值最少是多少. 额.....题意我是没看懂啦= =......看懂之后,就转化为最小生成树来做了.这是一个完全图,即每条边与除它之外的所有边都连通.边与边的权值是通过这个差值来算出来的. 1 #include <iostream> 2 #include <cstdio>

poj 1860 Currency Exchange 解题报告

题目链接:http://poj.org/problem?id=1860 题目意思:给出 N 种 currency, M种兑换方式,Nick 拥有的的currency 编号S 以及他的具体的currency(V).M 种兑换方式中每种用6个数描述: A, B, Rab, Cab, Rba, Cba.其中,Rab: 货币A 兑换 货币B 的汇率为Rab,佣金为Cab.Rba:货币B 兑换 货币 A 的汇率,佣金为Cba.假设含有的A货币是x,那么如果兑换成B,得到的货币B 就是:(x-Cab) *

poj 2531 Network Saboteur 解题报告

题目链接:http://poj.org/problem?id=2531 题目意思:将 n 个点分成两个部分A和B(也就是两个子集啦), 使得子集和最大(一定很难理解吧,呵呵).举个例子吧,对于样例,最佳的分法就是把点2分为一个子集,另一个子集理所当然就是1.3了. 2-1 的权值是50,2-3的权值是40,那么最大就是50+40 = 90了. 首先dfs的话,我不太会做啦.看了队长的用了状态压缩来做,一下子觉得好神奇!!!! 可能第一次接触,理解得不是太深刻,先留着吧.就觉得好神奇,好神奇...

poj 3368 Frequent values 解题报告

题目链接:http://poj.org/problem?id=3368 题目意思:给出一段 n 个数的序列你,对于区间 [l, r] 的询问,找出 出现频率最高的数的次数.考虑到序列中的数是非递减的,也就是相同的数会连续不间断地在一起,于是就才有了代码中这个部分来预判了: if (s > t)        printf("%d\n", ans); 这个人写RMQ 写得不错:http://dongxicheng.org/structure/lca-rmq/ 这题就是套模板的,纪念

poj 1325 Machine Schedule 解题报告

题目链接:http://poj.org/problem?id=1325 题目意思:有 k 个作业,机器A有 n 个模式:0 ~ n-1,机器B 有 m 个模式:0~ m-1.每一个作业能运行在 A 的 某一个模式(假设为 i (0 <= i <= n-1 ) )或 B 的某一个模式下(j (0 <= j <= m-1)).多个作业可以同时运行在 A 的某一个 模式下,当然 B 也如此.每对A 或 B 转换一次模式,就要重启一次 A 或者 B,你需要选择A 或 B 的一些模式,使得所

【原创】poj ----- 2524 Ubiquitous Religions 解题报告

题目地址: http://poj.org/problem?id=2524 题目内容: Ubiquitous Religions Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 26119   Accepted: 12859 Description There are so many different religions in the world today that it is difficult to keep tra

【原创】poj ----- 1611 The Suspects 解题报告

题目地址: http://poj.org/problem?id=1611 题目内容: The Suspects Time Limit: 1000MS   Memory Limit: 20000K Total Submissions: 24253   Accepted: 11868 Description Severe acute respiratory syndrome (SARS), an atypical pneumonia of unknown aetiology, was recogni

poj 2389.Bull Math 解题报告

题目链接:http://poj.org/problem?id=2389 题目意思:就是大整数乘法. 题目中说每个整数不超过 40 位,是错的!!!要开大点,这里我开到100. 其实大整数乘法还是第一次写 = =.......大整数加法写得比较多.百练也有一条是大整数乘法,链接如下:http://bailian.openjudge.cn/practice/2980/ 一步一步模拟即可,代码就是按这个来写的. 以 835 * 49 为例(亲爱的读者,允许我截图吧) 简直就是神奇呀----- 1 #i