4035800_ac_141ms_596k.cpp

来自「北大大牛代码 1240道题的原代码 超级权威」· C++ 代码 · 共 39 行

CPP
39
字号
#include <algorithm>

using namespace std;

struct node
{
    int x, y;
	bool operator < (const node &t)	const
	{
		return x < t.x || (x == t.x && y < t.y);
	}
}m[50002];

int main()
{
    int n, i, t, mac;

	while (scanf("%d", &n), n)
	{
		for (i = 0; i < n; i++)
		{
			scanf("%d%d", &m[i].x, &m[i].y);
		}
		sort(m, m + n);
		t = 1;
		mac = m[n - 1].y;
		for (i = n - 2; i >= 0; i--)
		{
			if(mac < m[i].y)
			{
				mac = m[i].y;
				t++;
			}
		}
		printf("%d\n", t);
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?