A15857 | Equalize by Divide
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given an array $a_1, a_2, \ldots, a_n$ of positive integers.
You can make this operation multiple (possibly zero) times:
- Choose two indices $i$ , $j$ ( $1 \leq i, j \leq n$ , $i \neq j$ ).
- Assign $a_i := \lceil \frac{a_i}{a_j} \rceil$ . Here $\lceil x \rceil$ denotes $x$ rounded up to the smallest integer $\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 $30n$ 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 $30n$ operations.
You can make this operation multiple (possibly zero) times:
- Choose two indices $i$ , $j$ ( $1 \leq i, j \leq n$ , $i \neq j$ ).
- Assign $a_i := \lceil \frac{a_i}{a_j} \rceil$ . Here $\lceil x \rceil$ denotes $x$ rounded up to the smallest integer $\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 $30n$ 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 $30n$ operations.
输入格式
The first line contains a single integer $t$ ( $1 \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 $n$ ( $1 \leq n \leq 100$ ).
The second line of each test case description contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^9$ ).
It is guaranteed, that the sum of $n$ for all test cases does not exceed $1000$ .
The first line of each test case description contains a single integer $n$ ( $1 \leq n \leq 100$ ).
The second line of each test case description contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^9$ ).
It is guaranteed, that the sum of $n$ for all test cases does not exceed $1000$ .
输出格式
For each test case print a single integer $q$ ( $-1 \leq q \leq 30n$ ). If $q=-1$ , there is no solution, otherwise $q$ is equal to the number of operations.
If $q \geq 0$ , on the next $q$ lines print two integers $i$ , $j$ ( $1 \leq i, j \leq n$ , $i \neq j$ ) — descriptions of operations.
If there are multiple solutions, you can print any.
If $q \geq 0$ , on the next $q$ lines print two integers $i$ , $j$ ( $1 \leq i, j \leq n$ , $i \neq j$ ) — descriptions of operations.
If there are multiple solutions, you can print any.
输入输出样例
输入 #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: $[\color{red}{4}, 3, \color{blue}{2}] \to [\color{blue}{2}, \color{red}{3}, 2] \to [2, 2, 2]$ .
In the sixth test case: $[\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 $i$ indices (that will be assigned), blue numbers are $j$ indices.
In the third test case, it is impossible to make all numbers equal.
In the fifth test case: $[\color{red}{4}, 3, \color{blue}{2}] \to [\color{blue}{2}, \color{red}{3}, 2] \to [2, 2, 2]$ .
In the sixth test case: $[\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 $i$ indices (that will be assigned), blue numbers are $j$ indices.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted