CF1854A1.Dual (Easy Version)
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
⠀
The only difference between the two versions of this problem is the constraint on the maximum number of operations. You can make hacks only if all versions of the problem are solved.
You are given an array a1,a2,…,an of integers (positive, negative or 0). You can perform multiple operations on the array (possibly 0 operations).
In one operation, you choose i,j (1≤i,j≤n, they can be equal) and set ai:=ai+aj (i.e., add aj to ai).
Make the array non-decreasing (i.e., ai≤ai+1 for 1≤i≤n−1) in at most 50 operations. You do not need to minimize the number of operations.
⠀
本题两个版本之间的唯一区别在于对最大操作次数的限制。仅当本题所有版本均已被解决时,你才可进行 Hack。
给定一个由整数(正数、负数或 0)构成的数组 a1,a2,…,an。你可以对数组执行多次操作(也可以不执行任何操作)。
每次操作中,你选择下标 i,j(满足 1≤i,j≤n,二者可以相等),并令 ai:=ai+aj(即把 aj 加到 ai 上)。
请在至多 50 次操作内使该数组变为非递减序列(即对所有 1≤i≤n−1,满足 ai≤ai+1)。你无需最小化操作次数。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤500). The description of the test cases follows.
The first line contains a single integer n (1≤n≤20) — the length of the array.
The second line contains n integers a1,a2,…,an (−20≤ai≤20) — the array before performing the operations.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤500)。随后是各测试用例的描述。
第一行包含一个整数 n(1≤n≤20)—— 数组的长度。
第二行包含 n 个整数 a1,a2,…,an(−20≤ai≤20)—— 执行操作前的数组。
输出格式
For each test case, output your operations in the following format.
The first line should contain an integer k (0≤k≤50) — the number of operations.
The next k lines represent the k operations in order. Each of these k lines should contain two integers i and j (1≤i,j≤n) — the corresponding operation consists in adding aj to ai.
After all the operations, the array a1,a2,…,an must be non-decreasing.
对于每个测试用例,请按以下格式输出你的操作。
第一行应包含一个整数 k(0≤k≤50)——表示操作的次数。
接下来的 k 行依次表示这 k 个操作。每行应包含两个整数 i 和 j(1≤i,j≤n)——对应的操作是将 aj 加到 ai 上。
执行完所有操作后,数组 a1,a2,…,an 必须是非递减的。
输入输出样例
输入#1
10 2 2 1 4 1 2 -10 3 5 2 1 1 1 1 8 0 0 0 0 0 0 0 0 5 1 2 -4 3 -10 10 11 12 13 14 15 -15 -16 -17 -18 -19 7 1 9 3 -4 -3 -2 -1 3 10 9 8 20 1 -14 2 -10 6 -5 10 -13 10 7 -14 19 -5 19 1 18 -16 -7 12 8 20 -15 -17 -13 8 14 -13 10 -4 11 -4 -16 -6 15 -4 -2 7 -9 5 -5 17
输出#1
1 2 1 3 4 4 4 4 3 4 4 2 1 3 1 4 1 5 1 0 7 3 4 3 4 5 4 5 4 5 4 5 4 5 4 15 6 1 6 1 6 1 7 2 7 2 7 2 8 3 8 3 8 3 9 4 9 4 9 4 10 5 10 5 10 5 8 3 4 3 4 2 4 2 4 2 4 2 4 1 4 1 4 3 2 1 3 1 3 1 31 14 1 18 7 13 11 15 11 6 4 5 17 19 6 19 12 10 5 11 12 1 17 15 19 16 10 14 2 16 11 20 7 7 6 9 5 3 6 6 14 17 18 18 14 12 3 17 16 8 18 13 16 9 8 14 8 16 2 11 8 12 7 31 5 12 19 13 9 1 5 17 18 19 6 16 15 8 6 9 15 14 7 10 19 7 17 20 14 4 15 20 4 3 1 8 16 12 16 15 5 6 12 10 11 15 20 3 20 19 13 14 11 14 18 10 7 3 12 17 4 7 13 2 11 13
说明/提示
In the first test case, by adding a1=2 to a2, we get the array [2,3] which is non-decreasing.
In the second test case, the array changes as:
- [1,2,−10,3]
- [1,2,−10,6]
- [1,2,−10,12]
- [1,2,2,12]
In the third test case, the final array is [2,3,3,3,3].
在第一个测试用例中,将 a1=2 加到 a2 上,得到数组 [2,3],该数组是非递减的。
在第二个测试用例中,数组的变化过程如下:
- [1,2,−10,3]
- [1,2,−10,6]
- [1,2,−10,12]
- [1,2,2,12]
在第三个测试用例中,最终数组为 [2,3,3,3,3]。
输入解题思路,AI测评打分。不知道怎么写?