0
点赞
收藏
分享

微信扫一扫

HDU 5744 Keep On Movin


Problem Description


i-th character is  ai. Professor Zhang wants to use all the characters build several palindromic strings. He also wants to maximize the length of the shortest palindromic string.

For example, there are 4 kinds of characters denoted as 'a', 'b', 'c', 'd' and the quantity of each character is  {2,3,2,2} . Professor Zhang can build {"acdbbbdca"}, {"abbba", "cddc"}, {"aca", "bbb", "dcd"}, or {"acdbdca", "bb"}. The first is the optimal solution where the length of the shortest palindromic string is 9.

Note that a string is called palindromic if it can be read the same way in either direction.


 



Input


There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer  n  (1≤n≤105) -- the number of kinds of characters. The second line contains  n integers  a1,a2,...,an  (0≤ai≤104).


 



Output


For each test case, output an integer denoting the answer.


 



Sample Input


4
4
1 1 2 4
3
2 2 2
5
1 1 1 1 1
5
1 1 2 2 3


 



Sample Output


3 6 1 3



简单题,统计一下奇数个数就好了。


#include<set>
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<bitset>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#define rep(i,j,k) for (int i = j; i <= k; i++)
#define per(i,j,k) for (int i = j; i >= k; i--)
using namespace std;
typedef long long LL;
const int low(int x) { return x&-x; }
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int INF = 0x7FFFFFFF;
int T, n, m, sum, odd;

int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
odd = sum = 0;
rep(i, 1, n)
{
scanf("%d", &m);
if (m & 1) odd++;
sum += m;
}
if (odd) printf("%d\n", (sum - odd) / 2 / odd * 2 + 1);
else printf("%d\n", sum);
}
return 0;
}



举报

相关推荐

0 条评论