CF1286A.Garland
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of n light bulbs in a single row. Each bulb has a number from 1 to n (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland. Now Vadim wants to put them back on.

Vadim wants to put all bulb back on the garland. Vadim defines complexity of a garland to be the number of pairs of adjacent bulbs with numbers with different parity (remainder of the division by 2). For example, the complexity of 1 4 2 3 5 is 2 and the complexity of 1 3 5 7 6 4 2 is 1.
No one likes complexity, so Vadim wants to minimize the number of such pairs. Find the way to put all bulbs back on the garland, such that the complexity is as small as possible.
瓦迪姆喜欢装饰圣诞树,因此他收到了一条漂亮的彩灯作为礼物。这条彩灯由一行 n 个灯泡组成。每个灯泡上标有一个从 1 到 n 的数字(顺序任意),且所有数字互不相同。当瓦迪姆正在解题时,他家的锦鲤(Carp)从彩灯上取下了一些灯泡。现在瓦迪姆想把它们重新装回去。

瓦迪姆希望将所有灯泡重新装回彩灯上。瓦迪姆将彩灯的复杂度定义为:相邻灯泡对中,两个灯泡编号奇偶性不同的对数(即两数除以 2 的余数不同)。例如,序列 1 4 2 3 5 的复杂度为 2,而序列 1 3 5 7 6 4 2 的复杂度为 1。
没人喜欢高复杂度,因此瓦迪姆希望最小化此类相邻对的数量。请找出一种将所有灯泡重新装回彩灯的方式,使得复杂度尽可能小。
输入格式
The first line contains a single integer n (1≤n≤100) — the number of light bulbs on the garland.
The second line contains n integers p1, p2, …, pn (0≤pi≤n) — the number on the i-th bulb, or 0 if it was removed.
第一行包含一个整数 n(1≤n≤100)—— 表示彩灯串上灯泡的数量。
第二行包含 n 个整数 p1, p2, …, pn(0≤pi≤n)—— 表示第 i 个灯泡上的数字;若该灯泡已被移除,则对应值为 0。
输出格式
Output a single number — the minimum complexity of the garland.
输出一个整数——彩灯串的最小复杂度。
输入输出样例
输入#1
5 0 5 0 2 3
输出#1
2
输入#2
7 1 0 0 5 0 0 2
输出#2
1
说明/提示
In the first example, one should place light bulbs as 1 5 4 2 3. In that case, the complexity would be equal to 2, because only (5,4) and (2,3) are the pairs of adjacent bulbs that have different parity.
In the second case, one of the correct answers is 1 7 3 5 6 4 2.
在第一个例子中,应将灯泡放置为 1 5 4 2 3。此时复杂度等于 2,因为仅有 (5,4) 和 (2,3) 这两对相邻灯泡具有不同的奇偶性。
在第二个例子中,一个正确的答案是 1 7 3 5 6 4 2。
输入解题思路,AI测评打分。不知道怎么写?