HDU 5744 Keep On Movin(胡搞)
来源:互联网 发布:打印机服务器软件 编辑:程序博客网 时间:2024/06/16 14:21
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
为数不多的水题
首先如果所有数出现次数都是偶数或只有一个奇数就可以全都放到一个回文串里奇数次的个数大1的直接算下和处理下分配就行
代码如下:
#include<bits/stdc++.h>using namespace std;int a[100005];int main(){ int n, t; scanf("%d",&t); while(t--){ int sum,num; num = sum = 0; scanf("%d", &n); for(int i = 1; i <= n; i++){ scanf("%d",&a[i]); if(a[i]%2){ num++; sum += (a[i]-1)/2; } else sum += a[i]/2; } int ans = max(1,num); printf("%d\n",(sum/ans)*2 + (num!=0)); } 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 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(贪心)
- hdu 5744 Keep On Movin (字符串)
- tomcat配置文件server.xml详解
- VB程序学习代码记录20160721
- 【离散数学】单向连通和弱连通的区别
- Codeforces Round #337 (Div. 2) A-----思维题
- Box of bricks 堆积木
- HDU 5744 Keep On Movin(胡搞)
- oralce存储过程双循环
- Android简介
- 欢迎使用CSDN-markdown编辑器
- 代理模式,简单(静态)工厂模式,单例模式,模板方法模式个人理解
- Hibernate灵活查询
- 16.对子集padding 对父级没有影响
- js替换字符串中所有/全部空格
- Android中的基础----各种LaunchMode的使用