CF1276E.Four Stones

NOI/NOI+/CTSC

通过率:0%

时间限制:1.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

There are four stones on an infinite line in integer coordinates a1,a2,a3,a4a_1, a_2, a_3, a_4. The goal is to have the stones in coordinates b1,b2,b3,b4b_1, b_2, b_3, b_4. The order of the stones does not matter, that is, a stone from any position aia_i can end up in at any position bjb_j, provided there is a required number of stones in each position (that is, if a coordinate xx appears kk times among numbers b1,…,b4b_1, \ldots, b_4, there should be exactly kk stones at xx in the end).

We are allowed to move stones with the following operation: choose two stones at distinct positions xx and yy with at least one stone each, and move one stone from xx to 2y−x2y - x. In other words, the operation moves a stone to a symmetric position relative to some other stone. At any moment it is allowed to have any number of stones at the same position.

Find any sequence of operations that achieves the goal, or determine that it is impossible. The sequence does not have to be shortest, but it may contain at most 10001000 operations.

在一条无限长的直线上有四颗石子,其坐标为整数 a1,a2,a3,a4a_1, a_2, a_3, a_4。目标是将这些石子移动至坐标 b1,b2,b3,b4b_1, b_2, b_3, b_4。石子的顺序无关紧要,即任意一颗位于 aia_i 的石子均可最终到达任意一个 bjb_j,但需满足每个目标坐标处的石子数量要求(即:若某坐标 xx 在 b1,…,b4b_1, \ldots, b_4 中恰好出现 kk 次,则最终必须恰好有 kk 颗石子位于 xx)。

允许执行如下操作来移动石子:选择两个位于不同位置 xx 和 yy 的石子(每个位置至少有一颗石子),并将其中一颗位于 xx 的石子移至位置 2y−x2y - x。换言之,该操作将一颗石子关于另一颗石子所在位置作对称移动。在任意时刻,允许多颗石子位于同一坐标。

请找出任意一个能达成目标的操作序列,或判定该目标无法实现。所求序列不必是最短的,但操作次数不得超过 10001000 次。

输入格式

The first line contains four integers a1,…,a4a_1, \ldots, a_4 (−109≤ai≤109-10^9 \leq a_i \leq 10^9) — initial coordinates of the stones. There may be multiple stones sharing the same coordinate.

The second line contains four integers b1,…,b4b_1, \ldots, b_4 (−109≤bi≤109-10^9 \leq b_i \leq 10^9) — target coordinates of the stones. There may be multiple targets sharing the same coordinate.

第一行包含四个整数 a1,…,a4a_1, \ldots, a_4(−109≤ai≤109-10^9 \leq a_i \leq 10^9),表示石头的初始坐标。可能存在多个石头位于同一坐标处。

第二行包含四个整数 b1,…,b4b_1, \ldots, b_4(−109≤bi≤109-10^9 \leq b_i \leq 10^9),表示石头的目标坐标。可能存在多个目标位于同一坐标处。

输出格式

If there is no sequence of operations that achieves the goal, print a single integer −1-1. Otherwise, on the first line print a single integer kk (0≤k≤10000 \leq k \leq 1000) — the number of operations in your sequence. On the next kk lines, describe the operations. The ii-th of these lines should contain two integers xix_i and yiy_i (xi≠yix_i \neq y_i) — coordinates of the moved stone and the center of symmetry stone for the ii-th operation.

For each operation ii, there should at least one stone in each of the coordinates xix_i and yiy_i, and the resulting coordinate 2yi−xi2y_i - x_i must not exceed 101810^{18} by absolute value.

If there are multiple suitable sequences, print any of them. It is guaranteed that if there is a suitable sequence of operations, then there is also a suitable sequence that satisfies all the additional requirement.

如果不存在能够达成目标的操作序列,则输出单个整数 −1-1。否则,第一行输出一个整数 kk(0≤k≤10000 \leq k \leq 1000),表示你所构造的操作序列的长度。接下来的 kk 行中,每行描述一次操作:第 ii 行应包含两个整数 xix_i 和 yiy_i(xi≠yix_i \neq y_i),分别表示第 ii 次操作中被移动的石子的坐标,以及作为对称中心的石子的坐标。

对于每次操作 ii,坐标 xix_i 和 yiy_i 处均必须至少存在一颗石子,且操作后石子的新坐标 2yi−xi2y_i - x_i 的绝对值不得超过 101810^{18}。

若存在多个满足条件的序列,输出任意一个即可。题目保证:若存在满足目标的操作序列,则必存在一个同时满足上述所有额外限制条件的操作序列。

输入输出样例

  • 输入#1

    0 1 2 3
    3 5 6 8

    输出#1

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

    0 0 0 0
    1 1 1 1

    输出#2

    -1
  • 输入#3

    0 0 0 1
    0 1 0 1

    输出#3

    -1

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

首页