CF1637G.Birthday
NOI/NOI+/CTSC
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vitaly gave Maxim n numbers 1,2,…,n for his 16-th birthday. Maxim was tired of playing board games during the celebration, so he decided to play with these numbers. In one step Maxim can choose two numbers x and y from the numbers he has, throw them away, and add two numbers x+y and ∣x−y∣ instead. He wants all his numbers to be equal after several steps and the sum of the numbers to be minimal.
Help Maxim to find a solution. Maxim's friends don't want to wait long, so the number of steps in the solution should not exceed 20n. It is guaranteed that under the given constraints, if a solution exists, then there exists a solution that makes all numbers equal, minimizes their sum, and spends no more than 20n moves.
维塔利在马克西姆16岁生日时送给了他 n 个数:1,2,…,n。庆祝活动中,马克西姆玩腻了桌游,于是决定用这些数字来玩游戏。每一步中,马克西姆可以从他当前拥有的数字中任选两个数 x 和 y,将它们丢弃,并替换成两个新数:x+y 和 ∣x−y∣。他希望经过若干步操作后,所有数字都相等,且此时所有数字的总和尽可能小。
请帮助马克西姆找到一个满足条件的方案。由于马克西姆的朋友们不愿久等,该方案的操作步数不得超过 20n。在给定约束下,若解存在,则必存在一个解,使得所有数字相等、总和最小,且操作步数不超过 20n。
输入格式
The first line contains a single integer t (1≤t≤25000) — the number of test cases.
Each test case contains a single integer n (2≤n≤5⋅104) — the number of integers given to Maxim.
It is guaranteed that the total sum of n doesn't exceed 5⋅104.
第一行包含一个整数 t(1≤t≤25000)—— 测试用例的数量。
每个测试用例包含一个整数 n(2≤n≤5⋅104)—— Maxim 所获得的整数个数。
保证所有测试用例中 n 的总和不超过 5⋅104。
输出格式
For each test case print −1 if it's impossible to make all numbers equal.
Otherwise print a single integer s (0≤s≤20n) — the number of steps. Then print s lines. The i-th line must contain two integers xi and yi — numbers that Maxim chooses on the i-th step. The numbers must become equal after all operations.
Don't forget that you not only need to make all numbers equal, but also minimize their sum. It is guaranteed that under the given constraints, if a solution exists, then there exists a solution that makes all numbers equal, minimizes their sum, and spends no more than 20n moves.
对于每个测试用例,如果无法使所有数字相等,则输出 −1。
否则,输出一个整数 s(0≤s≤20n)—— 所需的步数。随后输出 s 行,第 i 行必须包含两个整数 xi 和 yi —— Maxim 在第 i 步所选择的两个数。所有操作完成后,所有数字必须相等。
请注意:你不仅需要使所有数字相等,还需使它们的和最小。在给定约束下,若解存在,则必存在一个解,使得所有数字相等、其和最小,且总步数不超过 20n。
输入输出样例
输入#1
2 2 3
输出#1
-1 3 1 3 2 2 4 0
输入解题思路,AI测评打分。不知道怎么写?