CF475F.Meta-universe
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Consider infinite grid of unit cells. Some of those cells are planets.
Meta-universe M = {_p_1, _p_2, ..., p__k} is a set of planets. Suppose there is an infinite row or column with following two properties: 1) it doesn't contain any planet p__i of meta-universe M on it; 2) there are planets of M located on both sides from this row or column. In this case we can turn the meta-universe M into two non-empty meta-universes _M_1 and _M_2 containing planets that are located on respective sides of this row or column.
A meta-universe which can't be split using operation above is called a universe. We perform such operations until all meta-universes turn to universes.
Given positions of the planets in the original meta-universe, find the number of universes that are result of described process. It can be proved that each universe is uniquely identified not depending from order of splitting.
考虑一个无限大的单位格点网格,其中某些格点上存在行星。
元宇宙 M={p1,p2,…,pk} 是一组行星的集合。假设存在一条无限长的行或列,满足如下两个条件:
- 该行或列上不包含元宇宙 M 中的任何行星 pi;
- 在该行或列的两侧均存在 M 中的行星。
此时,我们可以将元宇宙 M 拆分为两个非空的元宇宙 M1 和 M2,分别包含位于该行或列两侧的行星。
无法通过上述操作进一步拆分的元宇宙称为宇宙(universe)。我们持续执行该拆分操作,直至所有元宇宙都变为宇宙。
给定原始元宇宙中各行星的坐标,请计算最终得到的宇宙个数。可以证明,每个宇宙的划分结果是唯一的,与拆分顺序无关。
输入格式
The first line of input contains an integer n, (1 ≤ n ≤ 105), denoting the number of planets in the meta-universe.
The next n lines each contain integers x__i and y__i, ( - 109 ≤ x__i, y__i ≤ 109), denoting the coordinates of the i-th planet. All planets are located in different cells.
输入的第一行包含一个整数 n(1≤n≤105),表示元宇宙中行星的数量。
接下来的 n 行,每行包含两个整数 xi 和 yi(−109≤xi,yi≤109),表示第 i 颗行星的坐标。所有行星均位于不同的格子中。
输出格式
Print the number of resulting universes.
输出最终的宇宙数量。
输入输出样例
输入#1
5 0 0 0 2 2 0 2 1 2 2
输出#1
3
输入#2
8 0 0 1 0 0 2 0 3 3 0 3 1 2 3 3 3
输出#2
1
说明/提示
The following figure describes the first test case:

下图描述了第一个测试用例:

输入解题思路,AI测评打分。不知道怎么写?