水题-HDU-5744-Keep On Movin
来源:互联网 发布:淘宝怎么能买到电棒 编辑:程序博客网 时间:2024/06/08 17:36
Keep On Movin
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 87 Accepted Submission(s): 73
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
2016 Multi-University Training Contest 2
题意:
给出字母种类数和各个类个数,求使用所有这些字母组成的回文串集合可行方案中,最短串的最大长度是多少。
题解:
很明显只要有出现奇数的,都得单独拿出来作为一个回文串的中央部分,那么统计奇数个数,将其余多的成对放置在两侧,最短的输出即可。
//// main.cpp// HDU-5744-Keep On Movin//// Created by 袁子涵 on 16/7/21.// Copyright © 2016年 袁子涵. All rights reserved.//#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <string>#include <bitset>#include <vector>#include <queue>#include <stack>#include <set>#include <map>#include <cstdlib>using namespace std;int t;long long int n,num,total1,total2,out;int main(void){ scanf("%d",&t); while (t--) { total1=total2=0; scanf("%lld",&n); for (long long int i=0; i<n; i++) { scanf("%lld",&num); if (num&1) total1++; total2+=num/2; } if (total1==0) out=total2*2; else out=2*(total2/total1)+1; printf("%lld\n",out); } return 0;}
- 水题-HDU-5744-Keep On Movin
- HDU 5744 Keep On Movin(水题)
- hdu 5744 Keep On Movin
- hdu 5744 Keep On Movin
- hdu 5744 Keep On Movin
- hdu 5744 Keep On Movin
- HDU 5744 ( Keep On Movin )
- HDU 5744 Keep On Movin
- HDU 5744 Keep On Movin
- 【HDU】5744 Keep On Movin
- hdu 5744 Keep On Movin
- HDU Keep On Movin
- Keep On Movin HDU
- Keep On Movin HDU
- HDU 5744 Keep On Movin(水题,思维题)
- HDU 5744 Keep On Movin(胡搞)
- Hdu 5744 Keep On Movin【思维】
- Hdu-5744 Keep On Movin(贪心)
- 一主多从快速变级联进行主从切换
- 【操作系统】滨江学院 陈遥 期末试卷考点整理
- 一维数组,二维数组,三维数组名的意义
- MySQL-Workbench --- 一款不错的数据库建模软件
- hdu5745 La Vie en rose(暴力)
- 水题-HDU-5744-Keep On Movin
- KafkaStreams介绍(二)
- 10进制与其他进制的转换
- UVaOJ 10935 Throwing cards away I
- nyoj 心急的C小加
- A - Can you find it?
- [Leetcod]154. Find Minimum in Rotated Sorted Array II
- 2016夏季练习——二叉树
- opencv读取摄像头数据