HDU 5744 Keep On Movin
Keep On Movin
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 76 Accepted Submission(s): 68
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.
#include <cstdio> int main()
{
int T, n;
scanf("%d", &T);
while(T--){
scanf("%d", &n);
int odd = 0; //记录奇数字符有多少个
int sum = 0; //记录总和
int num;
while(n--){
scanf("%d", &num);
if(num&1){
++odd;
sum += num-1;
}
else{
sum += num;
}
}
if(odd == 0){ //只有偶数字符
printf("%d\n", sum);
}
else{
sum >>= 1; //得到能够分配的对数
printf("%d\n", sum/odd*2+1);
}
}
return 0;
}
HDU 5744 Keep On Movin的更多相关文章
- HDU 5744 Keep On Movin (贪心)
Keep On Movin 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5744 Description Professor Zhang has k ...
- HDU 5744 Keep On Movin 贪心
Keep On Movin 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5744 Description Professor Zhang has k ...
- hdu 5744 Keep On Movin (2016多校第二场)
Keep On Movin Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- HDU 5744 Keep On Movin (贪心) 2016杭电多校联合第二场
题目:传送门. 如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了. #include <iostream ...
- 【HDU 5744】Keep On Movin
找出奇数个的数有几个,就分几组. #include<cstdio> #include<cstring> #include<algorithm> #include&l ...
- 2016 Multi-University Training Contest 2题解报告
A - Acperience HDU - 5734 题意: 给你一个加权向量,需要我们找到一个二进制向量和一个比例因子α,使得|W-αB|的平方最小,而B的取值为+1,-1,我们首先可以想到α为输入数 ...
- 类似区间计数的种类并查集两题--HDU 3038 & POJ 1733
1.POJ 1733 Parity game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5744 Accepted: ...
- HDOJ 2111. Saving HDU 贪心 结构体排序
Saving HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 【HDU 3037】Saving Beans Lucas定理模板
http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...
随机推荐
- 2013 ACM-ICPC长沙赛区全国邀请赛——Bottles Arrangement
这题当时竟然没看啊…… 找规律:求和m+m+m-1+m-1+……前n项 ;}
- Project Euler 91:Right triangles with integer coordinates 格点直角三角形
Right triangles with integer coordinates The points P (x1, y1) and Q (x2, y2) are plotted at integer ...
- 【Linux高频命令专题(7)】rm
简述 rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所有文件及子目录均删除.对于链接文件,只是删除了链接,原有文件均保持不变. 命令格式 rm [选项 ...
- Web 技术人员需知的Web 缓存知识
最近的译文距今已有4年之久,原文有一定的更新.今天踩着前辈们的肩膀,再次把这篇文章翻译整理下.一来让自己对web缓存的理解更深刻些,二来让大家注意力稍稍转移下,不要整天HTML5, 面试题啊叨啊叨的~ ...
- win32 api ShouCursor 根据内部计数器 是否>= 0 决定是否 显示光标,每true时计数器+1,每false-1
win32 api ShouCursor 根据内部计数器 是否>= 0 决定是否 显示光标,每true时计数器+1,每false-1,编程时true 和 false 的次数容易产生bug.
- word文档标题级别批量更改——批量降级与升级实例
word文档标题级别批量更改——批量降级与升级实例 word文档标题级别批量更改——批量降级实例 2012年12月21日16:30:44 现有一个3级文档结构的word文档,如下图所示 先需要将上 ...
- [HIHO1184]连通性二·边的双连通分量(双连通分量)
题目链接:http://hihocoder.com/problemset/problem/1184 题意裸,写个博客记下输出姿势. /* ━━━━━┒ギリギリ♂ eye! ┓┏┓┏┓┃キリキリ♂ mi ...
- 如何在Ubuntu上安装最新版本的Node.js
apt-get update apt-get install -y python-software-properties software-properties-common add-apt-repo ...
- add-two-numbers-ii
注意:有一种好的方法,是将链表倒转,然后依次相加. 但是,按照题目要求,用了不改变原链表的方法. 就是将两个链表增加到相同长度,然后递归相加,子函数返回后处理进位. https://leetcode. ...
- Android系列之Fragment(一)----Fragment加载到Activity当中
Android上 的界面展示都是通过Activity实现的,Activity实在是太常用了.但是Activity也有它的局限性,同样的界面在手机上显示可能很好看, 在平板上就未必了,因为平板的屏幕非常 ...