CF1616C.Representative Edges

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

An array a1,a2,…,ana_1, a_2, \ldots, a_n is good if and only if for every subsegment 1≤l≤r≤n1 \leq l \leq r \leq n, the following holds: al+al+1+…+ar=12(al+ar)⋅(r−l+1)a_l + a_{l + 1} + \ldots + a_r = \frac{1}{2}(a_l + a_r) \cdot (r - l + 1).

You are given an array of integers a1,a2,…,ana_1, a_2, \ldots, a_n. In one operation, you can replace any one element of this array with any real number. Find the minimum number of operations you need to make this array good.

数组 a1,a2,…,ana_1, a_2, \ldots, a_n 是“好”的,当且仅当对每个子段 1≤l≤r≤n1 \leq l \leq r \leq n,均满足:

al+al+1+…+ar=12(al+ar)⋅(r−l+1).a_l + a_{l + 1} + \ldots + a_r = \frac{1}{2}(a_l + a_r) \cdot (r - l + 1).

给定一个整数数组 a1,a2,…,ana_1, a_2, \ldots, a_n。每次操作中,你可以将该数组中的任意一个元素替换为任意实数。求使该数组变为“好”数组所需的最少操作次数。

输入格式

The first line of input contains one integer tt (1≤t≤1001 \leq t \leq 100): the number of test cases.

Each of the next tt lines contains the description of a test case.

In the first line you are given one integer nn (1≤n≤701 \leq n \leq 70): the number of integers in the array.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (−100≤ai≤100-100 \leq a_i \leq 100): the initial array.

输入的第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100):测试用例的数量。

接下来的 tt 行,每行描述一个测试用例。

在每个测试用例的第一行中,给出一个整数 nn(1≤n≤701 \leq n \leq 70):数组中整数的个数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(−100≤ai≤100-100 \leq a_i \leq 100):初始数组。

输出格式

For each test case, print one integer: the minimum number of elements that you need to replace to make the given array good.

对于每个测试用例,输出一个整数:使给定数组变为“好”数组所需替换的最少元素个数。

输入输出样例

  • 输入#1

    5
    4
    1 2 3 4
    4
    1 1 2 2
    2
    0 -1
    6
    3 -2 4 -1 -4 0
    1
    -100

    输出#1

    0
    2
    0
    3
    0

说明/提示

In the first test case, the array is good already.

In the second test case, one of the possible good arrays is [1,1,1‾,1‾][1, 1, \underline{1}, \underline{1}] (replaced elements are underlined).

In the third test case, the array is good already.

In the fourth test case, one of the possible good arrays is [−2.5‾,−2,−1.5‾,−1,−0.5‾,0][\underline{-2.5}, -2, \underline{-1.5}, -1, \underline{-0.5}, 0].

在第一个测试用例中,该数组已经是好数组。

在第二个测试用例中,一个可能的好数组是 [1,1,1‾,1‾][1, 1, \underline{1}, \underline{1}](被替换的元素用下划线标出)。

在第三个测试用例中,该数组已经是好数组。

在第四个测试用例中,一个可能的好数组是 [−2.5‾,−2,−1.5‾,−1,−0.5‾,0][\underline{-2.5}, -2, \underline{-1.5}, -1, \underline{-0.5}, 0]。

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

首页