hdu 5744(2016 Multi-University Training Contest 2)

Keep On Movin

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 338    Accepted Submission(s): 245


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
 

Author
zimpha
 

Source
2016 Multi-University Training Contest 2


 

题意:给定n个字符的个数,然后组合成若干的回文串,求这些回文串里最小的最长.........看不明白自己慢慢捋。

分析:回文串的个数是根据字符的奇数个的个数来决定的,然后平分偶数.....好水的说....

 

#include 
#include 
using namespace std;
int main()
{
    int T,i,j,n,m;
    scanf("%d",&T);
    while(T--)
    {
        int a=0,b=0,s=0;
        scanf("%d",&n);
        for(i=0;i


 

你可能感兴趣的:(ACM—多校,ACM—水,各OJ刷题专栏)