306951: CF1276E. Four Stones

Memory Limit:512 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Four Stones

题意翻译

### 题目描述 初始有四块石头分别放在数轴的$a_1,a_2,a_3,a_4$四个整点上(可能在某一个点上有多块石头),每一次操作中你可以选择两块不同的石头$(a_x,a_y)(1 \leq x,y \leq 4 , x \neq y)$将$a_x$变为$2a_y - a_x$。 给出四个目标位置$b_1,b_2,b_3,b_4$(不一定两两不同),试构造一个操作序列满足: - 操作结束后,存在一个排列$p_1,p_2,p_3,p_4$满足$a_{p_i} = b_i$; - 操作过程中不存在任何一个石头的位置的绝对值超过$10^{18}$; - 你不需要最小化操作序列长度,但是你需要保证操作序列长度$\leq 1000$。 题目保证如果存在一组操作序列满足第一个条件,则一定存在一组操作序列满足以上所有条件。 ### 输入格式 第一行四个整数$a_1,a_2,a_3,a_4$表示石头的初始位置,第二行四个整数$b_1,b_2,b_3,b_4$表示目标位置,所有输入的绝对值$\leq 10^9$。 ### 输出格式 如果不存在这样的操作序列输出`-1`,否则第一行输出一个整数$k(0 \leq k \leq 1000)$表示你给出的操作序列长度,接下来$k$行每行两个正整数$x,y(1 \leq x,y \leq 4 , x \neq y)$描述这一次操作

题目描述

There are four stones on an infinite line in integer coordinates $ a_1, a_2, a_3, a_4 $ . The goal is to have the stones in coordinates $ b_1, b_2, b_3, b_4 $ . The order of the stones does not matter, that is, a stone from any position $ a_i $ can end up in at any position $ b_j $ , provided there is a required number of stones in each position (that is, if a coordinate $ x $ appears $ k $ times among numbers $ b_1, \ldots, b_4 $ , there should be exactly $ k $ stones at $ x $ in the end). We are allowed to move stones with the following operation: choose two stones at distinct positions $ x $ and $ y $ with at least one stone each, and move one stone from $ x $ to $ 2y - 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 $ 1000 $ operations.

输入输出格式

输入格式


The first line contains four integers $ a_1, \ldots, a_4 $ ( $ -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 $ b_1, \ldots, b_4 $ ( $ -10^9 \leq b_i \leq 10^9 $ ) — target coordinates of the stones. There may be multiple targets sharing the same coordinate.

输出格式


If there is no sequence of operations that achieves the goal, print a single integer $ -1 $ . Otherwise, on the first line print a single integer $ k $ ( $ 0 \leq k \leq 1000 $ ) — the number of operations in your sequence. On the next $ k $ lines, describe the operations. The $ i $ -th of these lines should contain two integers $ x_i $ and $ y_i $ ( $ x_i \neq y_i $ ) — coordinates of the moved stone and the center of symmetry stone for the $ i $ -th operation. For each operation $ i $ , there should at least one stone in each of the coordinates $ x_i $ and $ y_i $ , and the resulting coordinate $ 2y_i - x_i $ must not exceed $ 10^{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

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

Input

题意翻译

### 题目描述 初始有四块石头分别放在数轴的$a_1,a_2,a_3,a_4$四个整点上(可能在某一个点上有多块石头),每一次操作中你可以选择两块不同的石头$(a_x,a_y)(1 \leq x,y \leq 4 , x \neq y)$将$a_x$变为$2a_y - a_x$。 给出四个目标位置$b_1,b_2,b_3,b_4$(不一定两两不同),试构造一个操作序列满足: - 操作结束后,存在一个排列$p_1,p_2,p_3,p_4$满足$a_{p_i} = b_i$; - 操作过程中不存在任何一个石头的位置的绝对值超过$10^{18}$; - 你不需要最小化操作序列长度,但是你需要保证操作序列长度$\leq 1000$。 题目保证如果存在一组操作序列满足第一个条件,则一定存在一组操作序列满足以上所有条件。 ### 输入格式 第一行四个整数$a_1,a_2,a_3,a_4$表示石头的初始位置,第二行四个整数$b_1,b_2,b_3,b_4$表示目标位置,所有输入的绝对值$\leq 10^9$。 ### 输出格式 如果不存在这样的操作序列输出`-1`,否则第一行输出一个整数$k(0 \leq k \leq 1000)$表示你给出的操作序列长度,接下来$k$行每行两个正整数$x,y(1 \leq x,y \leq 4 , x \neq y)$描述这一次操作

加入题单

算法标签: