CF1276E.Four Stones
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are four stones on an infinite line in integer coordinates a1,a2,a3,a4 . The goal is to have the stones in coordinates b1,b2,b3,b4 . The order of the stones does not matter, that is, a stone from any position ai can end up in at any position bj , provided there is a required number of stones in each position (that is, if a coordinate x appears k times among numbers b1,…,b4 , 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 a1,…,a4 ( −109≤ai≤109 ) — initial coordinates of the stones. There may be multiple stones sharing the same coordinate.
The second line contains four integers b1,…,b4 ( −109≤bi≤109 ) — 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≤k≤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 xi and yi ( xi=yi ) — 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 xi and yi , and the resulting coordinate 2yi−xi must not exceed 1018 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