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

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
 

题意:给出每种字符的个数,组成回文串,找出所有回文串中最小的,要尽量是它最大。

水题,注意理解题意。没有奇数的字母或者一个奇数的字母则直接连成一个回文串,直接输出所有字母的个数。若出现多(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 ;
}

hdu 5744 Keep On Movin (2016多校第二场)的更多相关文章

  1. hdu 5723 Abandoned country(2016多校第一场) (最小生成树+期望)

    Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  2. hdu 5745 La Vie en rose(2016多校第二场)

    La Vie en rose Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  3. hdu 5734 Acperience(2016多校第二场)

    Acperience Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  4. hdu 5742 It's All In The Mind(2016多校第二场)

    It's All In The Mind Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  5. HDU 4620 Fruit Ninja Extreme(2013多校第二场 剪枝搜索)

    这题官方结题报告一直在强调不难,只要注意剪枝就行. 这题剪枝就是生命....没有最优化剪枝就跪了:如果当前连续切割数加上剩余的所有切割数没有现存的最优解多的话,不需要继续搜索了 #include &l ...

  6. HDU 4614 Vases and Flowers (2013多校第二场线段树)

    题意摘自:http://blog.csdn.net/kdqzzxxcc/article/details/9474169 ORZZ 题意:给你N个花瓶,编号是0 到 N - 1 ,初始状态花瓶是空的,每 ...

  7. hdu 6045: Is Derek lying? (2017 多校第二场 1001)【找规律】

    题目链接 可以暴力找一下规律 比如,假设N=7,两人有5题相同,2题不同,枚举X=0->15时,Y的"Not lying"的取值范围从而找出规律 #include<bi ...

  8. 2019牛客多校第二场 A Eddy Walker(概率推公式)

    2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...

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

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

随机推荐

  1. Mac下载Navicat premium提示文件损坏的解决方案

    首先打开终端,执行: sudo bash 这时会提示你输入你的账户密码, 输入完后就切换到了 root 用户,然后执行: xattr -cr /Applications/Navicat\ Premiu ...

  2. UvaLive1347

    Programming contests became so popular in the year 2397 that the governor of New Earck — the largest ...

  3. for循环取出每个i的值

    <!DOCTYPE html> <html> <head> <title></title> </head> <body&g ...

  4. vs code 配置c/c++环境

    1. 编译 通过 code-runner插件 运行编译 安装code-runner后在settings.json中找到code-runner.executorMap,可以看到其中的cpp 文件运行方式 ...

  5. 如何把VS Code的Language Server Protocol整合到Eclipse中来

    Eclipse官方已经在着手做这件事情了,在Oxygen中,Eclipse提供了LSP4E扩展点(language server protocal for eclipse)来支持language se ...

  6. koa2路由

    注意:必须导出 文档地址:https://npm.taobao.org/package/koa-router 例: const router = require('koa-router')() rou ...

  7. Directx11教程39 纹理映射(9)

    原文:Directx11教程39 纹理映射(9)     在myTutorialD3D11_32中,我们在PlaneModelClass中增加一个纹理TextureClass* m_Texture;读 ...

  8. Failed to delete access_log

    重复build 关闭已经开启的tomcat    terminal 再次开启即可

  9. 部署zabbix3.2.7,升级到3.4、proxy部署

    一.Server安装 可以使用mysql.percona.mariadb等,本例使用mariadb.由于是事后整理,只截取部分命令. #yum install mariadb-server maria ...

  10. hdu4318 最短路变形

    和hdu有一题差不多.给的是损失比,1-c%就是保存了多少,找出最大的保存率即可. #include<stdio.h> #include<iostream> #include& ...