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 ...
随机推荐
- struts2学习笔记(2)——简单的输入验证以及标签库的运用
struts2自带了一些标签库,运用好这些标签库会减少开发周期. 1.struts2标签库是在哪定义的? struts2标签库定义在struts2-core-2.1.8.jar这个文件中,具体在这个j ...
- java 写文本文件
code 1:将特定String写入特定文件,不覆盖. import java.io.*; import java.util.*; public class OutputLog { public st ...
- cojs 简单的区间问题 解题报告
新学了些弦图和区间图的新玩意,于是就想着出一道题目 其实这道题不用弦图和区间图的理论也是可以做的 首先考虑第一问,第一问是一个NOIP普及组水平的贪心 我们把区间按照右端点从小到大排序,之后从头到尾扫 ...
- Linux 线程模型的比较:LinuxThreads 和 NPTL
Linux 线程模型的比较:LinuxThreads 和 NPTL GNU_LIBPTHREAD_VERSION 宏 大部分现代 Linux 发行版都预装了 LinuxThreads 和 NPTL,因 ...
- iOS:自定义工具栏、导航栏、标签栏
工具栏为UIToolBar,导航栏UINavigationBar,标签栏UITabBar.它们的样式基本上时差不多的,唯一的一点区别就是,工具栏一般需要自己去创建,然后添加到视图中,而导航栏和标签栏不 ...
- Servlet编写登录界面
package com.mhb; import java.io.IOException;import java.io.PrintWriter; import javax.servlet.Servlet ...
- sql server 自定义函数的使用
sql server 自定义函数的使用 自定义函数 用户定义自定义函数像内置函数一样返回标量值,也可以将结果集用表格变量返回 用户自定义函数的类型: 标量函数:返回一个标量值 表格值函数{内联表格值函 ...
- SVN update: 'skipped' message
在eclipse中用svn插件同步google code老是服务器连接time out!就只有通过检出项目再更新啦,结果遇到个SVN update: 'skipped' message问题,还是sta ...
- PHP的线程安全与非线程安全版本的区别
Windows版的PHP从版本5.2.1开始有Thread Safe(线程安全)和None Thread Safe(NTS,非线程安全)之分,这两者不同在于何处?到底应该用哪种?这里做一个简单的介绍. ...
- sql partition by 的使用
select a.bs_sn, a.bs_bd_no, a.bs_bk_code, a.bs_kind_no, a.bs_flag, b.det_flag, c.bp_in_no, c.bp_name ...