hdu 5744 Keep On Movin (2016多校第二场)
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
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.
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) .
answer.
题意:给出每种字符的个数,组成回文串,找出所有回文串中最小的,要尽量是它最大。
水题,注意理解题意。没有奇数的字母或者一个奇数的字母则直接连成一个回文串,直接输出所有字母的个数。若出现多(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多校第二场)的更多相关文章
- hdu 5723 Abandoned country(2016多校第一场) (最小生成树+期望)
Abandoned country Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- 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 ...
- hdu 5734 Acperience(2016多校第二场)
Acperience Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- 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 ...
- HDU 4620 Fruit Ninja Extreme(2013多校第二场 剪枝搜索)
这题官方结题报告一直在强调不难,只要注意剪枝就行. 这题剪枝就是生命....没有最优化剪枝就跪了:如果当前连续切割数加上剩余的所有切割数没有现存的最优解多的话,不需要继续搜索了 #include &l ...
- HDU 4614 Vases and Flowers (2013多校第二场线段树)
题意摘自:http://blog.csdn.net/kdqzzxxcc/article/details/9474169 ORZZ 题意:给你N个花瓶,编号是0 到 N - 1 ,初始状态花瓶是空的,每 ...
- hdu 6045: Is Derek lying? (2017 多校第二场 1001)【找规律】
题目链接 可以暴力找一下规律 比如,假设N=7,两人有5题相同,2题不同,枚举X=0->15时,Y的"Not lying"的取值范围从而找出规律 #include<bi ...
- 2019牛客多校第二场 A Eddy Walker(概率推公式)
2019牛客多校第二场 A Eddy Walker(概率推公式) 传送门:https://ac.nowcoder.com/acm/contest/882/A 题意: 给你一个长度为n的环,标号从0~n ...
- HDU 5744 Keep On Movin (贪心) 2016杭电多校联合第二场
题目:传送门. 如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了. #include <iostream ...
随机推荐
- git命令移动文件夹到另一文件夹
- UE4物理模块(二)---建立物体碰撞
在前文中介绍了什么是物理以及如何在UE4和PhysX中进行可视化调试: Jerry:UE4物理模块(一)---概述与可视化调试zhuanlan.zhihu.com 这里调试只谈到了碰撞盒(后续还会有 ...
- ML面试1000题系列(61-70)
本文总结ML面试常见的问题集 转载来源:https://blog.csdn.net/v_july_v/article/details/78121924 61.说说共轭梯度法? @wtq1993,htt ...
- GCC/GDB学习
GCC学习 1.gcc是根据后缀名来区分文件的 .c : c语言源文件 .a : 目标文件构成的库文件 .C/.cc/.cxx : c++源文件 .h : 头文件 .i : 预处理过的C源文件 .ii ...
- 初次接触python的re模块
刷CF的时候,看到一个简单的题目,可以用来练练正则表达式 于是乎找到了re.sub的用法,说明如下 re.sub: (pattern, repl, string, count=0, │ f ...
- arcgis人口专题图
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- windows中将网络共享文件夹映射为网络硬盘
目的是: 实现局域网,不同电脑之间共享文件. 例如: 计划将A电脑 的文件夹C:\MM ,共享给局域网电脑 B. 局域网所有电脑都可访问: 1. 在A电脑中 共享文件夹..选择‘启用网络发现’ ‘ ...
- Codeforces Beta Round #77 (Div. 2 Only) A. Football【字符串/判断是否存在连续7个0或7个1】
A. Football time limit per test 2 seconds memory limit per test 256 megabytes input standard input o ...
- 2019-2-16-WPF-封装-dotnet-remoting-调用其他进程
title author date CreateTime categories WPF 封装 dotnet remoting 调用其他进程 lindexi 2019-02-16 09:40:26 +0 ...
- 洛谷P1541 乌龟棋 [2010NOIP提高组]
P1541 乌龟棋 题目背景 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物. 题目描述 乌龟棋的棋盘是一行N个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一的起点,第N格是终点,游戏要求玩家 ...