2016 Multi-University Training Contest 2 1011 Keep On Movin

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5744

题目:

Problem Description
Professor Zhang has kinds of characters and the quantity of the 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 (1n105) -- the number of kinds of characters. The second line contains n integers a1,a2,...,an (0ai104) .
 

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


考虑奇数的个数,小于2时只有1个回文串,大于等于2时,奇数的个数等于回文串的个数。

#include <iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#define ll long long
using namespace std;

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        int n;
        scanf("%d",&n);
        int team=0;
        int sum=0;
        for(int i=0;i<n;i++)
        {
            int t;
            scanf("%d",&t);
            if(t&1==1) team++;
            sum+=t;
        }
        if(team==0||team==1)    printf("%d\n",sum);
        else
        {
            sum-=team;
            sum/=(2*team);
            sum*=2;
            printf("%d\n",sum+1);
        }
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值