CF1651D.Nearest Excluded Points

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given nn distinct points on a plane. The coordinates of the ii-th point are (xi,yi)(x_i, y_i).

For each point ii, find the nearest (in terms of Manhattan distance) point with integer coordinates that is not among the given nn points. If there are multiple such points — you can choose any of them.

The Manhattan distance between two points (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2) is ∣x1−x2∣+∣y1−y2∣|x_1 - x_2| + |y_1 - y_2|.

给你平面上的 nn 个互不相同的点。第 ii 个点的坐标为 (xi,yi)(x_i, y_i)。

对每个点 ii,找出一个曼哈顿距离(Manhattan distance)最近的、坐标均为整数且不在给定的 nn 个点之中的点。若存在多个满足条件的点,则任选其一即可。

两点 (x1,y1)(x_1, y_1) 与 (x2,y2)(x_2, y_2) 之间的曼哈顿距离定义为 ∣x1−x2∣+∣y1−y2∣|x_1 - x_2| + |y_1 - y_2|。

输入格式

The first line of the input contains one integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5) — the number of points in the set.

The next nn lines describe points. The ii-th of them contains two integers xix_i and yiy_i (1≤xi,yi≤2⋅1051 \le x_i, y_i \le 2 \cdot 10^5) — coordinates of the ii-th point.

It is guaranteed that all points in the input are distinct.

输入的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 表示集合中点的个数。

接下来的 nn 行描述这些点。其中第 ii 行包含两个整数 xix_i 和 yiy_i(1≤xi,yi≤2⋅1051 \le x_i, y_i \le 2 \cdot 10^5)—— 表示第 ii 个点的坐标。

保证输入中所有点互不相同。

输出格式

Print nn lines. In the ii-th line, print the point with integer coordinates that is not among the given nn points and is the nearest (in terms of Manhattan distance) to the ii-th point from the input.

Output coordinates should be in range [−106;106][-10^6; 10^6]. It can be shown that any optimal answer meets these constraints.

If there are several answers, you can print any of them.

输出 nn 行。在第 ii 行中,输出一个整数坐标点,该点不在给定的 nn 个点之中,且在曼哈顿距离意义下,是离输入中第 ii 个点最近的点。

输出坐标的取值范围必须在 [−106, 106][-10^6,\, 10^6] 内。可以证明:任意最优解均满足此约束。

若存在多个合法答案,输出其中任意一个即可。

输入输出样例

  • 输入#1

    6
    2 2
    1 2
    2 1
    3 2
    2 3
    5 5

    输出#1

    1 1
    1 1
    2 0
    3 1
    2 4
    5 4
  • 输入#2

    8
    4 4
    2 4
    2 2
    2 3
    1 4
    4 2
    1 3
    3 3

    输出#2

    4 3
    2 5
    2 1
    2 5
    1 5
    4 1
    1 2
    3 2

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

首页