CF1917A.Least Product

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an array of integers a1,a2,…,ana_1, a_2, \dots, a_n. You can perform the following operation any number of times (possibly zero):

  • Choose any element aia_i from the array and change its value to any integer between 00 and aia_i (inclusive). More formally, if ai<0a_i \lt 0, replace aia_i with any integer in [ai,0][a_i, 0], otherwise replace aia_i with any integer in [0,ai][0, a_i].

Let rr be the minimum possible product of all the aia_i after performing the operation any number of times.

Find the minimum number of operations required to make the product equal to rr. Also, print one such shortest sequence of operations. If there are multiple answers, you can print any of them.

给你一个整数数组 a1,a2,…,ana_1, a_2, \dots, a_n。你可以执行以下操作任意次(包括零次):

  • 任选数组中的一个元素 aia_i,将其值更改为 00 到 aia_i(含端点)之间的任意整数。更准确地说:若 ai<0a_i \lt 0,则将 aia_i 替换为区间 [ai,0][a_i, 0] 中的任意整数;否则(即 ai≥0a_i \ge 0),将 aia_i 替换为区间 [0,ai][0, a_i] 中的任意整数。

设 rr 为经过任意次操作后所有 aia_i 的乘积所能达到的最小可能值。

求使乘积恰好等于 rr 所需的最少操作次数,并输出一种达到该最少次数的操作序列。若存在多种答案,输出任意一种即可。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤5001 \leq t \leq 500) - the number of test cases. This is followed by their description.

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

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

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

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

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

输出格式

For each test case:

  • The first line must contain the minimum number of operations kk (0≤k≤n0 \leq k \leq n).
  • The jj-th of the next kk lines must contain two integers ii and xx, which represent the jj-th operation. That operation consists in replacing aia_i with xx.

对于每个测试用例:

  • 第一行必须包含最小操作次数 kk(0≤k≤n0 \leq k \leq n)。
  • 接下来的 kk 行中,第 jj 行必须包含两个整数 ii 和 xx,表示第 jj 次操作。该操作将 aia_i 替换为 xx。

输入输出样例

  • 输入#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 00 and the product will become 00, which is the minimum possible.

In the second test case, initially, the product of integers is equal to 2⋅8⋅(−1)⋅3=−482 \cdot 8 \cdot (-1) \cdot 3 = -48 which is the minimum possible, so we should do nothing in this case.

在第一个测试用例中,我们可以将第一个整数的值改为 00,此时乘积变为 00,这是可能的最小值。

在第二个测试用例中,初始时整数的乘积为 2⋅8⋅(−1)⋅3=−482 \cdot 8 \cdot (-1) \cdot 3 = -48,这已经是可能的最小值,因此在此情况下我们无需进行任何操作。

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

首页