五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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ó)家法律
宣威市| 嘉黎县| 大丰市| 开江县| 苏尼特左旗| 禄丰县| 深水埗区| 吴旗县| 蓝田县| 西昌市| 博爱县| 措美县| 奉节县| 定陶县| 双鸭山市| 祁东县| 江山市| 五河县| 兰溪市| 梧州市| 吴旗县| 云南省| SHOW| 德惠市| 永嘉县| 彩票| 乌兰察布市| 刚察县| 乌拉特前旗| 霍林郭勒市| 施甸县| 通辽市| 个旧市| 辽宁省| 新平| 息烽县| 许昌市| 桐城市| 曲松县| 库尔勒市| 阜城县|