307741: CF1407A. Ahahahahahahahaha
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Ahahahahahahahaha
题意翻译
## 题目描述 Alexandra 有一个由若干$0$和$1$组成的数组$a$,且数组$a$的长度$n$为偶数,数列中所有元素的编号依次为$1$ ~ $n$。她希望在数组中删除一些元素,来使得奇数编号位置上的数字之和等于偶数编号位置上的数字之和($a_1 - a_2 + a_3 - a_4 + ... = 0$),最多删除$\frac{n}{2}$个元素且删除的元素不必是连续的 例如,如果原数组$a$ = $\left[1,0,1,0,0,0\right]$,且她删除了原数列中的第$2$个和第$4$个元素,那么数组$a$将变成$\left[1,1,0,0\right]$,并且奇数编号位置上的数字之和等于偶数编号位置上的数字之和。 帮帮她解决这个问题吧! ## 输入格式 每个测试点包含多组样例,输入的第一行包含一个数字t,表示样例的组数。($1 \le t \le 10^3$ ) 接下来每两行为一组样例,其中第一行包含一个整数$n$,表示数组的长度。($2 \le n \le 10^3$ 且 n为偶数) 第二行包含n个整数,分别为数组中的每个元素 $a_1, a_2, a_3, ... , a_n$。($0 \le a_i \le 1$ ) 输入数据保证所有测试点中$n$的和不超过$10^3$。 ## 输出格式 对于每组样例,第一行输出$k$,用来表示经过删除操作后数组$a$中剩下的元素个数。($\frac{n}{2} \le k \le n$) 然后在第二行中,输出这剩下的$k$个数字。注意是输出这些数字本身,而不是输出他们的编号。 显而易见的是答案必然会存在至少一个,如果有多个答案,你可以输出其中的任何一个答案。题目描述
Alexandra has an even-length array $ a $ , consisting of $ 0 $ s and $ 1 $ s. The elements of the array are enumerated from $ 1 $ to $ n $ . She wants to remove at most $ \frac{n}{2} $ elements (where $ n $ — length of array) in the way that alternating sum of the array will be equal $ 0 $ (i.e. $ a_1 - a_2 + a_3 - a_4 + \dotsc = 0 $ ). In other words, Alexandra wants sum of all elements at the odd positions and sum of all elements at the even positions to become equal. The elements that you remove don't have to be consecutive. For example, if she has $ a = [1, 0, 1, 0, 0, 0] $ and she removes $ 2 $ nd and $ 4 $ th elements, $ a $ will become equal $ [1, 1, 0, 0] $ and its alternating sum is $ 1 - 1 + 0 - 0 = 0 $ . Help her!输入输出格式
输入格式
Each test contains multiple test cases. The first line contains the number of test cases $ t $ ( $ 1 \le t \le 10^3 $ ). Description of the test cases follows. The first line of each test case contains a single integer $ n $ ( $ 2 \le n \le 10^3 $ , $ n $ is even) — length of the array. The second line contains $ n $ integers $ a_1, a_2, \ldots, a_n $ ( $ 0 \le a_i \le 1 $ ) — elements of the array. It is guaranteed that the sum of $ n $ over all test cases does not exceed $ 10^3 $ .
输出格式
For each test case, firstly, print $ k $ ( $ \frac{n}{2} \leq k \leq n $ ) — number of elements that will remain after removing in the order they appear in $ a $ . Then, print this $ k $ numbers. Note that you should print the numbers themselves, not their indices. We can show that an answer always exists. If there are several answers, you can output any of them.
输入输出样例
输入样例 #1
4
2
1 0
2
0 0
4
0 1 1 1
4
1 1 0 0
输出样例 #1
1
0
1
0
2
1 1
4
1 1 0 0