CF1799B.Equalize by Divide

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array a1,a2,…,ana_1, a_2, \ldots, a_n of positive integers.

You can make this operation multiple (possibly zero) times:

  • Choose two indices ii, jj (1≤i,j≤n1 \leq i, j \leq n, i≠ji \neq j).
  • Assign ai:=⌈aiaj⌉a_i := \lceil \frac{a_i}{a_j} \rceil. Here ⌈x⌉\lceil x \rceil denotes xx rounded up to the smallest integer ≥x\geq x.

Is it possible to make all array elements equal by some sequence of operations (possibly empty)? If yes, print any way to do it in at most 30n30n operations.

It can be proven, that under the problem constraints, if some way exists to make all elements equal, there exists a way with at most 30n30n operations.

给你一个由正整数构成的数组 a1,a2,…,ana_1, a_2, \ldots, a_n。

你可以执行以下操作任意次(可能为零次):

  • 选择两个下标 ii、jj(满足 1≤i,j≤n1 \leq i, j \leq n 且 i≠ji \neq j);
  • 将 aia_i 赋值为 ⌈aiaj⌉\lceil \frac{a_i}{a_j} \rceil。其中 ⌈x⌉\lceil x \rceil 表示不小于 xx 的最小整数(即 xx 向上取整)。

是否可以通过若干次(可能为空)操作,使得数组中所有元素相等?如果可以,请输出任意一种操作方案,且操作次数不超过 30n30n 次。

在本题约束下可以证明:若存在某种方式使所有元素相等,则必存在一种操作次数不超过 30n30n 的方案。

输入格式

The first line contains a single integer tt (1≤t≤10001 \leq t \leq 1000) — the number of test cases. Descriptions of test cases follow.

The first line of each test case description contains a single integer nn (1≤n≤1001 \leq n \leq 100).

The second line of each test case description contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9).

It is guaranteed, that the sum of nn for all test cases does not exceed 10001000.

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \leq n \leq 100)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)。

保证所有测试用例的 nn 值之和不超过 10001000。

输出格式

For each test case print a single integer qq (−1≤q≤30n-1 \leq q \leq 30n). If q=−1q=-1, there is no solution, otherwise qq is equal to the number of operations.

If q≥0q \geq 0, on the next qq lines print two integers ii, jj (1≤i,j≤n1 \leq i, j \leq n, i≠ji \neq j) — descriptions of operations.

If there are multiple solutions, you can print any.

对于每个测试用例,输出一个整数 qq(−1≤q≤30n-1 \leq q \leq 30n)。若 q=−1q = -1,表示无解;否则 qq 等于操作次数。

若 q≥0q \geq 0,则在接下来的 qq 行中,每行输出两个整数 ii、jj(1≤i,j≤n1 \leq i, j \leq n,且 i≠ji \neq j),表示对应的操作。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    10
    1
    100
    3
    1 1 1
    2
    2 1
    2
    5 5
    3
    4 3 2
    4
    3 3 4 4
    2
    2 100
    5
    5 3 6 7 8
    6
    3 3 80 3 8 3
    4
    19 40 19 55

    输出#1

    0
    0
    -1
    0
    2
    1 3
    2 1
    4
    3 1
    4 2
    1 3
    2 4
    6
    2 1
    2 1
    2 1
    2 1
    2 1
    2 1
    8
    5 2
    4 2
    3 2
    1 3
    1 3
    2 1
    4 1
    5 1
    4
    5 1
    3 1
    3 1
    3 1
    9
    4 2
    2 1
    1 2
    1 2
    3 2
    3 2
    1 4
    2 4
    3 4

说明/提示

In the first and second, fourth test cases all numbers are equal, so it is possible to do nothing.

In the third test case, it is impossible to make all numbers equal.

In the fifth test case: [4,3,2]→[2,3,2]→[2,2,2][\color{red}{4}, 3, \color{blue}{2}] \to [\color{blue}{2}, \color{red}{3}, 2] \to [2, 2, 2].

In the sixth test case: [3,3,4,4]→[3,3,2,4]→[3,3,2,2]→[2,3,2,2]→[2,2,2,2][\color{blue}{3}, 3, \color{red}{4}, 4] \to [3, \color{blue}{3}, 2, \color{red}{4}] \to [\color{red}{3}, 3, \color{blue}{2}, 2] \to [2, \color{red}{3}, 2, \color{blue}{2}] \to [2, 2, 2, 2].

Here the red numbers are ii indices (that will be assigned), blue numbers are jj indices.

在第一和第二个、第四个测试用例中,所有数字均相等,因此无需进行任何操作。

在第三个测试用例中,无法使所有数字相等。

在第五个测试用例中:[4,3,2]→[2,3,2]→[2,2,2][\color{red}{4}, 3, \color{blue}{2}] \to [\color{blue}{2}, \color{red}{3}, 2] \to [2, 2, 2]。

在第六个测试用例中:[3,3,4,4]→[3,3,2,4]→[3,3,2,2]→[2,3,2,2]→[2,2,2,2][\color{blue}{3}, 3, \color{red}{4}, 4] \to [3, \color{blue}{3}, 2, \color{red}{4}] \to [\color{red}{3}, 3, \color{blue}{2}, 2] \to [2, \color{red}{3}, 2, \color{blue}{2}] \to [2, 2, 2, 2]。

此处红色数字表示 ii 下标(将被赋值),蓝色数字表示 jj 下标。

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

首页