hdu 5744 Keep On Movin (2016多校第二场)
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
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.
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) .
answer.
题意:给出每种字符的个数,组成回文串,找出所有回文串中最小的,要尽量是它最大。
水题,注意理解题意。没有奇数的字母或者一个奇数的字母则直接连成一个回文串,直接输出所有字母的个数。若出现多(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 ;
}
最新文章
- 玩转Vim 编辑器
- 【代码笔记】iOS-正方形转换
- java中文文档官方下载
- C++ 画星号图形——空心梯形(核心代码记录)
- Java-坦克大战
- 【JavaScript】 knockout.js 日期格式化借助【momentjs】
- 点餐APP 冲刺一总结
- 背景大图隔几秒切换(非轮播,淡入淡出)--变形金刚joy007 项目总结
- Netty笔记--ByteBuf释放
- Unity3D基础学习 NGUI之Example 13 - Tabs简要概述
- 为什么IIS中找不到.net framework 4.5(转)
- iReport 4.1 报表制作,子报表,实例解析
- a标签文字选中后的颜色样式更改
- ACM Find them, Catch them
- 微信小程序开发01-小程序的执行流程是怎么样的?
- 多条件搜索优化sql
- Maven项目打包成可执行Jar文件
- mongoDB的使用(NodeJs)
- shell 多线程
- react 使用antd 按需加载
热门文章
- 系统日志和内核消息 $ dmesg$ less /var/log/messages$ less /var/log/secure$ less /var/log/auth
- Liferay 7:Liferay Nexus
- 编译libusb库
- 【python小随笔】celery周期任务(简单原理)
- SQL SERVER 2008 R2 插入数据非常慢
- Spring_Bean的生命周期
- mysql中的year(date)和date_format(date,format)的用法
- 显示调用dll
- [转] javascript核心
- WPF程序国际化