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

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
 
Source
 
 
 
解析:如果每个字符出现的次数都是偶数,结果显然为各字符出现的次数之和。如果含有奇数,则奇数1+2k(k>=0)可分为1和2k,2k和其他偶数相加得到总和,再把得到的和平均分给奇数字符即可。
 
 
 
#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的更多相关文章

  1. HDU 5744 Keep On Movin (贪心)

    Keep On Movin 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5744 Description Professor Zhang has k ...

  2. HDU 5744 Keep On Movin 贪心

    Keep On Movin 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5744 Description Professor Zhang has k ...

  3. hdu 5744 Keep On Movin (2016多校第二场)

    Keep On Movin Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  4. HDU 5744 Keep On Movin (贪心) 2016杭电多校联合第二场

    题目:传送门. 如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了. #include <iostream ...

  5. 【HDU 5744】Keep On Movin

    找出奇数个的数有几个,就分几组. #include<cstdio> #include<cstring> #include<algorithm> #include&l ...

  6. 2016 Multi-University Training Contest 2题解报告

    A - Acperience HDU - 5734 题意: 给你一个加权向量,需要我们找到一个二进制向量和一个比例因子α,使得|W-αB|的平方最小,而B的取值为+1,-1,我们首先可以想到α为输入数 ...

  7. 类似区间计数的种类并查集两题--HDU 3038 & POJ 1733

    1.POJ 1733 Parity game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5744   Accepted: ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. Zabbix 安装及微信短信提醒

    Zabbix简介 Zabbix 近几年得到了各大互联网公司的认可,当然第一点归功与它强大的监控功能,第二点免费开源也得到了广大用户的青睐.Zabbix 能将操作系统中的绝大部分指标进行监控,比如(CP ...

  2. Create a method synchronized without using synchronized keyword

    Actually, lots of ways: No need for synchronization at all if you don't have mutable state. No need ...

  3. POJ 1785 Binary Search Heap Construction(裸笛卡尔树的构造)

    笛卡尔树: 每个节点有2个关键字key.value.从key的角度看,这是一颗二叉搜索树,每个节点的左子树的key都比它小,右子树都比它大:从value的角度看,这是一个堆. 题意:以字符串为关键字k ...

  4. HDU 4509 湫湫系列故事——减肥记II(暴力模拟即可)

    看了题目后,没自己做,直接看别人题解了,这里转一下. 看了之后,突然想起scanf还可以按照自己写的格式输入数据啊,差点连这个都忘记了啊. 注意输入中时间可能有重复的. http://www.cnbl ...

  5. javascript加速运动

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  6. javascript分享到的源码

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...

  7. 2013 Multi-University Training Contest 1 I-number

    水题,注意不要去掉前导0…… ;}

  8. Git fetch和git pull的区别(转)

    原文: http://www.tech126.com/git-fetch-pull/ Git中从远程的分支获取最新的版本到本地有这样2个命令:1. git fetch:相当于是从远程获取最新版本到本地 ...

  9. 李洪强iOS开发之零基础学习iOS开发】【02-C语言】01-概述

    前面已经给大家介绍了iOS开发相关的一些基础知识,其实iOS开发就是开发iPhone\iPad上的软件,而要想开发一款软件,首先要学习程序设计语言.iOS开发需要学习的主要程序设计语言有:C语言.C+ ...

  10. JDK安装配置问题

    JDK安装过程中会有两个安装提示,一个是jdk的安装,一个是jre的安装