CF1519E.Off by One

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn points on an infinite plane. The ii-th point has coordinates (xi,yi)(x_i, y_i) such that xi>0x_i \gt 0 and yi>0y_i \gt 0. The coordinates are not necessarily integer.

In one move you perform the following operations:

  • choose two points aa and bb (a≠ba \neq b);
  • move point aa from (xa,ya)(x_a, y_a) to either (xa+1,ya)(x_a + 1, y_a) or (xa,ya+1)(x_a, y_a + 1);
  • move point bb from (xb,yb)(x_b, y_b) to either (xb+1,yb)(x_b + 1, y_b) or (xb,yb+1)(x_b, y_b + 1);
  • remove points aa and bb.

However, the move can only be performed if there exists a line that passes through the new coordinates of aa, new coordinates of bb and (0,0)(0, 0).

Otherwise, the move can't be performed and the points stay at their original coordinates (xa,ya)(x_a, y_a) and (xb,yb)(x_b, y_b), respectively.

The numeration of points does not change after some points are removed. Once the points are removed, they can't be chosen in any later moves. Note that you have to move both points during the move, you can't leave them at their original coordinates.

What is the maximum number of moves you can perform? What are these moves?

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

无限平面上有 nn 个点。第 ii 个点的坐标为 (xi,yi)(x_i, y_i),满足 xi>0x_i > 0 且 yi>0y_i > 0。坐标不一定是整数。

每次操作执行以下步骤:

  • 选择两个不同的点 aa 和 bb(a≠ba \neq b);
  • 将点 aa 从 (xa,ya)(x_a, y_a) 移动至 (xa+1,ya)(x_a + 1, y_a) 或 (xa,ya+1)(x_a, y_a + 1);
  • 将点 bb 从 (xb,yb)(x_b, y_b) 移动至 (xb+1,yb)(x_b + 1, y_b) 或 (xb,yb+1)(x_b, y_b + 1);
  • 删除点 aa 和 bb。

但该操作仅当存在一条直线,同时经过点 aa 的新坐标、点 bb 的新坐标以及原点 (0,0)(0, 0) 时,才允许执行。

否则,该操作不可执行,点 aa 和 bb 分别保持在原坐标 (xa,ya)(x_a, y_a) 和 (xb,yb)(x_b, y_b) 处。

点的编号在部分点被删除后保持不变。一旦点被删除,后续操作中便不能再选择它们。注意:每次操作中必须移动两个点,不能让它们停留在原坐标。

你最多能执行多少次操作?这些操作分别是什么?

若存在多种答案,输出任意一种即可。

输入格式

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

The ii-th of the next nn lines contains four integers ai,bi,ci,dia_i, b_i, c_i, d_i (1≤ai,bi,ci,di≤1091 \le a_i, b_i, c_i, d_i \le 10^9). The coordinates of the ii-th point are xi=aibix_i = \frac{a_i}{b_i} and yi=cidiy_i = \frac{c_i}{d_i}.

第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 点的数量。

接下来的 nn 行中,第 ii 行包含四个整数 ai,bi,ci,dia_i, b_i, c_i, d_i(1≤ai,bi,ci,di≤1091 \le a_i, b_i, c_i, d_i \le 10^9)。第 ii 个点的坐标为 xi=aibix_i = \frac{a_i}{b_i} 和 yi=cidiy_i = \frac{c_i}{d_i}。

输出格式

In the first line print a single integer cc — the maximum number of moves you can perform.

Each of the next cc lines should contain a description of a move: two integers aa and bb (1≤a,b≤n1 \le a, b \le n, a≠ba \neq b) — the points that are removed during the current move. There should be a way to move points aa and bb according to the statement so that there's a line that passes through the new coordinates of aa, the new coordinates of bb and (0,0)(0, 0). No removed point can be chosen in a later move.

If there are multiple answers, you can print any of them. You can print the moves and the points in the move in the arbitrary order.

第一行输出一个整数 cc —— 你能执行的最大移动次数。

接下来的 cc 行,每行应描述一次移动:两个整数 aa 和 bb(1≤a,b≤n1 \le a, b \le n,a≠ba \neq b)—— 表示当前移动中被移除的点。必须存在一种按题意对点 aa 和 bb 进行移动的方式,使得一条直线能同时经过 aa 的新坐标、bb 的新坐标以及原点 (0,0)(0, 0)。任何已被移除的点均不可在后续移动中再次被选中。

若存在多种合法答案,输出任意一种即可。移动的顺序以及每次移动中两点的顺序均可任意。

输入输出样例

  • 输入#1

    7
    4 1 5 1
    1 1 1 1
    3 3 3 3
    1 1 4 1
    6 1 1 1
    5 1 4 1
    6 1 1 1

    输出#1

    3
    1 6
    2 4
    5 7
  • 输入#2

    4
    2 1 1 1
    1 1 2 1
    2 1 1 2
    1 2 1 2

    输出#2

    1
    1 2
  • 输入#3

    4
    182 168 60 96
    78 72 45 72
    69 21 144 63
    148 12 105 6

    输出#3

    1
    2 4

说明/提示

Here are the points and the moves for the ones that get chosen for the moves from the first example:

以下是第一个示例中被选中用于移动的点及其对应的移动方式:

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

首页