HDU Keep On Movin
来源:互联网 发布:java 校验身份证号码 编辑:程序博客网 时间:2024/05/19 07:10
Keep On Movin
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 568 Accepted Submission(s): 385
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.
For example, there are 4 kinds of characters denoted as 'a', 'b', 'c', 'd' and the quantity of each character is
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 integern (1≤n≤105) -- the number of kinds of characters. The second line contains n integers a1,a2,...,an (0≤ai≤104) .
The first line contains an integer
Output
For each test case, output an integer denoting the answer.
Sample Input
441 1 2 432 2 251 1 1 1 151 1 2 2 3
Sample Output
3613#include <iostream>#include <algorithm>#include <cstdio>using namespace std;int main(){ int t; scanf("%d", &t); while(t--) { int n, tmp, sum=0, ans=0; scanf("%d", &n); for(int i=0;i<n;i++) { scanf("%d", &tmp); if(tmp&1) { ans++; sum+=(tmp-1)/2; } else { sum+=tmp/2; } } if(ans==0) { printf("%d\n",sum*2); } else if(sum%ans==0) { printf("%d\n",(sum/ans)*2+1); } else { printf("%d\n",(sum/ans)*2+1); } } return 0;}
0 0
- 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 )
- 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 (字符串)
- 关于android中的BuildConfig
- BootStrap 列表组件
- 谈谈MVC模式
- 计算机考试相关证书 (二)
- iOS NSURLCache(网络缓存)
- HDU Keep On Movin
- http状态码有哪些?代表什么意思?(查询手册而已)
- BootStrap 面板组件
- CentOS 7.2 添加磁盘并创建新区
- a small test for array
- Android 回调
- New Year and Days
- 1072. Gas Station (30)
- 高并发系统之限流特技:有了它,京东6.18如虎添翼!