最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

CF 1367B - Even Array

2023-07-25 15:44 作者:您是打尖兒還是住店呢  | 我要投稿

You are given an array a[0…n?1] of length n which consists of non-negative integers. Note that array indices start from zero.


An array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all i

?(0≤i≤n?1) the equality imod2=a[i]mod2 holds, where xmod2

?is the remainder of dividing x by 2.

For example, the arrays [0,5,2,1] and [0,17,0,3] are good, and the array [2,4,6,7] is bad, because for i=1, the parities of i and a[i] are different: imod2=1mod2=1, but a[i]mod2=4mod2=0.

In one move, you can take any two elements of the array and swap them (these elements are not necessarily adjacent).

Find the minimum number of moves in which you can make the array a good, or say that this is not possible.


Input

The first line contains a single integer t (1≤t≤1000) — the number of test cases in the test. Then t test cases follow.

Each test case starts with a line containing an integer n (1≤n≤40) — the length of the array a

.


The next line contains n integers a0,a1,…,an?1 (0≤ai≤1000) — the initial array.

Output

For each test case, output a single integer — the minimum number of moves to make the given array a good, or -1 if this is not possible

----------------------------------------------------------------------

給定一個(gè)長(zhǎng)度為 n 的數(shù)組 a[0…n?1],它由非負(fù)整數(shù)組成。 請(qǐng)注意,數(shù)組索引從零開始。


如果每個(gè)索引的奇偶校驗(yàn)與該索引處元素的奇偶校驗(yàn)匹配,則稱該數(shù)組為良好數(shù)組。 更正式地說(shuō),如果對(duì)于所有 i 來(lái)說(shuō),數(shù)組就是好的

? (0≤i≤n?1) 等式 imod2=a[i]mod2 成立,其中 xmod2

? 是 x 除以 2 的余數(shù)。

例如,數(shù)組 [0,5,2,1] 和 [0,17,0,3] 是好的,而數(shù)組 [2,4,6,7] 是壞的,因?yàn)閷?duì)于 i=1,i 和 a[i] 的奇偶性不同:imod2=1mod2=1,但 a[i]mod2=4mod2=0。

一步操作中,您可以取出數(shù)組中的任意兩個(gè)元素并交換它們(這些元素不一定相鄰)。

求出可以使數(shù)組變好的最小移動(dòng)次數(shù),或者說(shuō)這是不可能的。


輸入

第一行包含一個(gè)整數(shù) t (1≤t≤1000) — 測(cè)試中測(cè)試用例的數(shù)量。 然后是測(cè)試用例。

每個(gè)測(cè)試用例都以包含整數(shù) n (1≤n≤40) 的行開始 — 數(shù)組 a 的長(zhǎng)度

。


下一行包含 n 個(gè)整數(shù) a0,a1,…,an?1 (0≤ai≤1000) — 初始數(shù)組。

輸出

對(duì)于每個(gè)測(cè)試用例,輸出一個(gè)整數(shù) - 使給定數(shù)組良好的最小移動(dòng)次數(shù),如果不可能,則輸出 -1

--------------------------------------

判斷奇數(shù)索引上面偶數(shù)的數(shù)量和偶數(shù)索引上面奇數(shù)的數(shù)量是否一致,如果一致,那么可以組成,如果不一致,就輸出-1;

下面是代碼:


CF 1367B - Even Array的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
桦川县| 车致| 余江县| 雷州市| 邹城市| 内丘县| 邵阳县| 石嘴山市| 修水县| 丘北县| 平舆县| 锦州市| 四子王旗| 鹿泉市| 格尔木市| 承德县| 漳州市| 隆安县| 基隆市| 阜康市| 西昌市| 遵义县| 镇远县| 岳池县| 定安县| 建始县| 绵竹市| 惠州市| 聊城市| 梅州市| 漯河市| 武义县| 塘沽区| 庆阳市| 湄潭县| 临朐县| 宁化县| 高尔夫| 体育| 大足县| 晋江市|