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. js实现放大镜特效的实现方法

    <!doctype html><html lang="en"><head> <meta charset="UTF-8" ...

  2. web前端学习(四)JavaScript学习笔记部分(1)-- JavaScript基础教程

    1.JavaScript基础教程 1.1.Javascript基础-介绍.实现.输出 1.1.1.JavaScript是互联网上最流行的脚本语言,这门语言可用于web和HTML,更可广泛用于服务端.p ...

  3. C# 详解反射

    原博客:http://www.cnblogs.com/Stephenchao/p/4481995.html 两个现实中的例子: 1.B超:大家体检的时候大概都做过B超吧,B超可以透过肚皮探测到你内脏的 ...

  4. [Vue CLI 3] vue inspect 的源码设计实现

    首先,请记住: 它在新版本的脚手架项目里面非常重要 它有什么用呢? inspect internal webpack config 能快速地在控制台看到对应生成的 webpack 配置对象. 首先它是 ...

  5. 【转载】【技巧总结】PyCharm怎么克隆github上开源的项目

    PyCharm怎么clone github上开源的项目 一.先要确保PyCharm正确的配置了Git   如果你已经在PyCharm中配置好了Git,可以跳过此步骤,直接看下一步.   那么怎么在Py ...

  6. 安装mongoDB时,总是报错,启动不了

    安装教程地址:https://blog.csdn.net/fengtingyan/article/details/88371232 原文地址:https://blog.csdn.net/qq_2008 ...

  7. 基于jQuery的自定义滚动条

    在线演示 本地下载

  8. vuxdemo1

    //main.js import Vue from 'vue' import router from './router' import store from './store' import axi ...

  9. 基于GD库的php验证码类(支持中英文字体、背景、干扰点线、扭曲…….)

    转自:http://www.blhere.com/1168.html 12345678910111213141516171819202122232425262728293031323334353637 ...

  10. 【JZOJ4893】【NOIP2016提高A组集训第15场11.14】过河

    题目描述 数据范围 解法 由于同一个点,同一个圆盘最多只会走一次. 把(i,j)当作一个点,表示第i个点,放第i个圆盘. 那么就可以使用最短路. 时间复杂度为O(n4∗k). 事实上存在冗余圆盘,一个 ...