poj-Monkeys'Pride

原创 2018年04月14日 23:33:07

描述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.

输入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.输出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.

样例输入

3
2 1
1 2
3 3
3
0 1
1 0
0 0
4
0 0
1 0
0 1
1 1
0

样例输出

1
2
1

解题思路:

这个题本身不难,但是要好好理解。比如最高点不一定满足point[i].x+point[i].y始终是最大值,即最高的横纵坐标之和不一定相等。比如(5,0),(0,4),这两个点都是最高点。可采用先对x排序,再对y排序的思路。

# include<stdio.h>
# include<algorithm>
using namespace std;

struct E
{
	int x;
	int y;
	bool operator < (const E &b) const
	{
	    if(x<b.x) return true;
		else if(x==b.x)
			return y<b.y;//升序

		return false;
	}
}po[50001];

int main()
{
    int n,i;
	while(scanf("%d",&n)!=EOF&&n)
	{
		int cnt=1;
		int max=-1,maxX=-1,maxY=-1;
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&po[i].x,&po[i].y);
		}
		sort(po,po+n);//升序

		int maxv=po[n-1].y;
        for(i=n-2;i>=0;i--)
		{
		    if(po[i].y>maxv)
			{
				cnt++;
				maxv=po[i].y;
			}
		}

        printf("%d\n",cnt);

	}
	return 0;
}

poj1828-Monkeys' Pride

题目大意: 题目给出n个点,求出有多少点满足没有横纵坐标同时大于等于这个点的个数。也就是在这所有的点中,这样的点有多少个?什么样的点呢?设这个点(x0,y0),那么如果不存在(x,y)使得x>=x0...
  • zhang20072844
  • zhang20072844
  • 2011-08-15 23:53:51
  • 1129

codeforces Pride 892C

题目链接: 892C Pride 大意: 给出一排数字,对这一排数字做一些操作如下: 每次对相邻的数字取 gcd,将结果赋给其中一个值。 求最少需要多少次操作 使得所有数字全为 1思路: ...
  • Joovo
  • Joovo
  • 2017-11-18 19:41:09
  • 256

Codeforces Round #446(div 2) C. Pride

C. Pride time limit per test2 seconds memory limit per test256 megabytes inputstandard input out...
  • Pandauncle
  • Pandauncle
  • 2017-11-18 12:19:15
  • 386

Codeforces Round #446 (Div. 2) C Pride

推规律 #include #include #include #include #include #include #include #include #include #include #...
  • xiang_6
  • xiang_6
  • 2017-11-18 11:58:52
  • 135

Codeforces 892 C. Pride (枚举)

Description You have an array a with length n, you can perform operations. Each operation is like ...
  • qq_28954601
  • qq_28954601
  • 2017-11-18 11:17:52
  • 479

Pride and Prejudice .pdf

  • 2012年02月17日 09:37
  • 1.08MB
  • 下载

CodeForces - 892C Pride GCD

CodeForces - 892C Pride GCD 题意:给你一个数列,有操作:对于相邻两个数,可以替换其中一个数为这两个数的gcd。求多少次操作后该数列全为1,不存在输出-1。 题解:可以发现,...
  • weixin_36571742
  • weixin_36571742
  • 2017-11-24 10:06:43
  • 112

【思维】Codeforces892C Pride

周六,总结一下这个星期的三把CF和紫书暴力章节。都是泪orz。 杭州打完铁之后,意识到思路慢的问题,练习了前几场CF的C题,感觉都还不错,结果到正式比赛那天晚上就。虽然不算太慢地发现了思路,但是没有...
  • nymph_h
  • nymph_h
  • 2017-11-25 12:45:45
  • 35

cf891A Pride 题解

有史以来第一次rating为正..手速之力是无穷的!(雾) 这题还是蛮有趣..想到了区间DP但是发现转移不动,还是naive..来看看题意。一串数,每次只能将相邻两个元素中的一个变成1,问要求最少多...
  • LiRewriter
  • LiRewriter
  • 2017-11-18 12:00:37
  • 105

CodeForces - 892C Pride (n个数,求相邻两个数的最大公约数替换其中一个数,看要操作几次使得n个数全部变成1)

You have an array a with length n, you can perform operations. Each operation is like this: choose t...
  • obsorb_knowledge
  • obsorb_knowledge
  • 2017-11-28 21:51:39
  • 127
收藏助手
不良信息举报
您举报文章:poj-Monkeys'Pride
举报原因:
原因补充:

(最多只允许输入30个字)