CF1691A.Beat The Odds

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Given a sequence a1,a2,…,ana_1, a_2, \ldots, a_n, find the minimum number of elements to remove from the sequence such that after the removal, the sum of every 22 consecutive elements is even.

给定一个序列 a1,a2,…,ana_1, a_2, \ldots, a_n,求需要从该序列中删除的最少元素个数,使得删除后任意两个相邻元素的和均为偶数。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. Description of the test cases follows.

The first line of each test case contains a single integer nn (3≤n≤1053 \le n \le 10^5).

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2,\dots,a_n (1≤ai≤1091\leq a_i\leq10^9) — elements of the sequence.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

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

每个测试用例的第一行包含一个整数 nn(3≤n≤1053 \le n \le 10^5)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2,\dots,a_n(1≤ai≤1091\leq a_i\leq10^9),表示序列的元素。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

For each test case, print a single integer — the minimum number of elements to remove from the sequence such that the sum of every 22 consecutive elements is even.

对于每个测试用例,输出一个整数——即需要从序列中删除的最少元素个数,使得剩余序列中任意两个相邻元素的和均为偶数。

输入输出样例

  • 输入#1

    2
    5
    2 4 3 6 8
    6
    3 5 9 7 1 3

    输出#1

    1
    0

说明/提示

In the first test case, after removing 33, the sequence becomes [2,4,6,8][2,4,6,8]. The pairs of consecutive elements are [2,4],[4,6],[6,8]{[2, 4], [4, 6], [6, 8]}. Each consecutive pair has an even sum now. Hence, we only need to remove 11 element to satisfy the condition asked.

In the second test case, each consecutive pair already has an even sum so we need not remove any element.

在第一个测试用例中,删除 33 后,序列变为 [2,4,6,8][2,4,6,8]。相邻元素对为 [2,4],[4,6],[6,8]{[2, 4], [4, 6], [6, 8]}。此时每一对相邻元素的和均为偶数。因此,我们只需删除 11 个元素即可满足题目所要求的条件。

在第二个测试用例中,每一对相邻元素的和原本就是偶数,因此无需删除任何元素。

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

首页