CF1917A.Least Product
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array of integers a1,a2,…,an. You can perform the following operation any number of times (possibly zero):
- Choose any element ai from the array and change its value to any integer between 0 and ai (inclusive). More formally, if ai<0, replace ai with any integer in [ai,0], otherwise replace ai with any integer in [0,ai].
Let r be the minimum possible product of all the ai after performing the operation any number of times.
Find the minimum number of operations required to make the product equal to r. Also, print one such shortest sequence of operations. If there are multiple answers, you can print any of them.
给你一个整数数组 a1,a2,…,an。你可以执行以下操作任意次(包括零次):
- 任选数组中的一个元素 ai,将其值更改为 0 到 ai(含端点)之间的任意整数。更准确地说:若 ai<0,则将 ai 替换为区间 [ai,0] 中的任意整数;否则(即 ai≥0),将 ai 替换为区间 [0,ai] 中的任意整数。
设 r 为经过任意次操作后所有 ai 的乘积所能达到的最小可能值。
求使乘积恰好等于 r 所需的最少操作次数,并输出一种达到该最少次数的操作序列。若存在多种答案,输出任意一种即可。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤500) - the number of test cases. This is followed by their description.
The first line of each test case contains the a single integer n (1≤n≤100) — the length of the array.
The second line of each test case contains n integers a1,a2,…,an (−109≤ai≤109).
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤500),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤100)—— 表示数组的长度。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(−109≤ai≤109)。
输出格式
For each test case:
- The first line must contain the minimum number of operations k (0≤k≤n).
- The j-th of the next k lines must contain two integers i and x, which represent the j-th operation. That operation consists in replacing ai with x.
对于每个测试用例:
- 第一行必须包含最小操作次数 k(0≤k≤n)。
- 接下来的 k 行中,第 j 行必须包含两个整数 i 和 x,表示第 j 次操作。该操作将 ai 替换为 x。
输入输出样例
输入#1
4 1 155 4 2 8 -1 3 4 -1 0 -2 -5 4 -15 -75 -25 -30
输出#1
1 1 0 0 0 1 3 0
说明/提示
In the first test case, we can change the value of the first integer into 0 and the product will become 0, which is the minimum possible.
In the second test case, initially, the product of integers is equal to 2⋅8⋅(−1)⋅3=−48 which is the minimum possible, so we should do nothing in this case.
在第一个测试用例中,我们可以将第一个整数的值改为 0,此时乘积变为 0,这是可能的最小值。
在第二个测试用例中,初始时整数的乘积为 2⋅8⋅(−1)⋅3=−48,这已经是可能的最小值,因此在此情况下我们无需进行任何操作。
输入解题思路,AI测评打分。不知道怎么写?