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 ...
随机推荐
- UVA 10246 Asterix and Obelix
题意:每个城市举办庆祝有一定的花费,A在路径上会选择庆祝花费最大的城市 让你求,A回家所花的路费和庆祝费最少,也就是说并不是最短路径就是结果, 还有可能就是路费比最短路径的多,但是庆祝费就比它的少,总 ...
- 【leetcode】Add Two Numbers(middle) ☆
You are given two linked lists representing two non-negative numbers. The digits are stored in rever ...
- 为什么很多应用都安装在/usr/local目录下
为什么很多应用都安装在/usr/local目录下 很多应用都安装在/usr/local下面,那么,这些应用为什么选择这个目录呢?理解了最根源的原因后,也许对你理解linux组织文件的方式有更直观的 ...
- leetcode 5 :Longest Palindromic Substring 找出最长回文子串
题目: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...
- [topcoder] EllysNumberGuessing
http://community.topcoder.com/stat?c=problem_statement&pm=12975 简单题 #include <cstdlib> #in ...
- 向ArcMap添加未出现的工具 如planarize lines
打开某工具的customize 找到你要添加的工具 将其拖到你要放置的工具条即可
- mongodb 常见操作转
Ø Collection聚集集合 1.创建一个聚集集合(table) db.createCollection(“collName”, {size: 20, capped: 5, max: 100}); ...
- 车牌识别LPR(二)-- 车牌特征及难点
第二篇:车牌的特征及难点 2.1 对我国车牌的认识 我国目前使用的汽车牌号标准是 2007 年开始实施的<中华人民共和国机动车号牌>GA36-2007(2010 年修订).根据 GA36 ...
- STL容器的效率比较
1.介绍 顺序存储容器 : string.vector.list.deque 关联存储容器:map底层采用的是树型结构,多数使用平衡二叉树实现,查找某一值是常数时间,遍历起来效果也不错, 只是每次插入 ...
- NDK(18)使用C++ STL
1,在Application.mk 中使用 APP_STL := stlport_static 等. APP_ABI := x86 armeabi APP_PLATFORM := android-15 ...