Keep On Movin

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

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 (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
 
Author
zimpha
 

题意:给出每种字符的个数,组成回文串,找出所有回文串中最小的,要尽量是它最大。

水题,注意理解题意。没有奇数的字母或者一个奇数的字母则直接连成一个回文串,直接输出所有字母的个数。若出现多(a)个奇数的字母,则分成a个回文串,平分剩下的偶数字母,输出此时最短的回文串数目。

附上代码:

 #include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int T,i,j,n,m;
scanf("%d",&T);
while(T--)
{
int a=,b=,s=;
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d",&m);
if(m%) a++; ///记录奇数出现的个数
s+=m; ///字母的总个数
}
if(!a||a==) ///如果只有一组奇数字母组或者没有奇数的字母组,则可以拼成一个回文串
{
printf("%d\n",s);
continue;
}
b=(s-a)/a/*+; ///出现多组奇数字母组的情况
printf("%d\n",b);
}
return ;
}

最新文章

  1. 玩转Vim 编辑器
  2. 【代码笔记】iOS-正方形转换
  3. java中文文档官方下载
  4. C++ 画星号图形——空心梯形(核心代码记录)
  5. Java-坦克大战
  6. 【JavaScript】 knockout.js 日期格式化借助【momentjs】
  7. 点餐APP 冲刺一总结
  8. 背景大图隔几秒切换(非轮播,淡入淡出)--变形金刚joy007 项目总结
  9. Netty笔记--ByteBuf释放
  10. Unity3D基础学习 NGUI之Example 13 - Tabs简要概述
  11. 为什么IIS中找不到.net framework 4.5(转)
  12. iReport 4.1 报表制作,子报表,实例解析
  13. a标签文字选中后的颜色样式更改
  14. ACM Find them, Catch them
  15. 微信小程序开发01-小程序的执行流程是怎么样的?
  16. 多条件搜索优化sql
  17. Maven项目打包成可执行Jar文件
  18. mongoDB的使用(NodeJs)
  19. shell 多线程
  20. react 使用antd 按需加载

热门文章

  1. 系统日志和内核消息 $ dmesg$ less /var/log/messages$ less /var/log/secure$ less /var/log/auth
  2. Liferay 7:Liferay Nexus
  3. 编译libusb库
  4. 【python小随笔】celery周期任务(简单原理)
  5. SQL SERVER 2008 R2 插入数据非常慢
  6. Spring_Bean的生命周期
  7. mysql中的year(date)和date_format(date,format)的用法
  8. 显示调用dll
  9. [转] javascript核心
  10. WPF程序国际化