您的位置:首页 > 大数据 > 人工智能

hdu 5744(2016 Multi-University Training Contest 2)

2016-07-22 11:40 531 查看

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



[align=left]Problem Description[/align]
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.

[align=left]Input[/align]
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).

[align=left]Output[/align]
For each test case, output an integer denoting the answer.

[align=left]Sample Input[/align]

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


[align=left]Sample Output[/align]

3
6
1
3


[align=left]Author[/align]
zimpha

[align=left]Source[/align]
2016 Multi-University Training
Contest 2

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

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

#include <iostream>
#include <cstdio>
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<n;i++)
{
scanf("%d",&m);
if(m%2) a++;
s+=m;
}
if(!a||a==1)
{
printf("%d\n",s);
continue;
}
b=(s-a)/a/2*2+1;
printf("%d\n",b);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: