hdu5744 Keep On Movin(水)
来源:互联网 发布:mysql增删改查 编辑:程序博客网 时间:2024/06/05 03:58
思路:如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了.
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <cmath>#include <cstdlib>#include <ctime>#define INF 0x3f3f3f3f#define esp 1e-9typedef long long LL;using namespace std;const int maxn = 100000 + 100;int a[maxn];int main(){ //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); int ca, n; scanf("%d", &ca); while(ca--) { scanf("%d", &n); LL sum = 0, rec=0; for(int i=0;i<n;++i) { scanf("%d", &a[i]); sum+=a[i]; if(a[i]&1) rec++; } if(rec==0) printf("%d\n", sum); else { sum -= rec; LL t = sum / rec; if(t%2==0) t++; printf("%lld\n", t); } } return 0;}
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
0 0
- hdu5744 Keep On Movin(水)
- HDU5744 Keep On Movin
- HDU5744 Keep On Movin(贪心)
- (多校第二场1011)HDU5744 Keep On Movin
- hdu5744——Keep On Movin(构造回文)
- HDU 5744 Keep On Movin(水题)
- hdu 5744 Keep On Movin (字符串)
- HDU 5744 Keep On Movin(贪心)
- Keep On Movin
- HDU Keep On Movin
- Keep On Movin
- Keep On Movin
- Keep On Movin
- Keep On Movin HDU
- Keep On Movin
- Keep On Movin HDU
- hdu 5744 Keep On Movin
- hdu 5744 Keep On Movin
- Notepad++ 快捷键整理
- Notification通知
- Yii2.0自带验证码使用心得分享 [ 2.0 版本 ]
- 贪心-HDU-5742-It's All In The Mind
- OC_模糊搜索(精华版)
- hdu5744 Keep On Movin(水)
- 如何制作.9png
- Codeforces 77BFalling Anvils
- 2016 Multi-University Training Contest 2 HDU 5744 Keep On Movin
- 操作系统知识点
- 循环队列java实现
- PHP使用3DES算法加密解密字符串
- Remove Duplicates from Sorted Array II
- Hibernate的核心接口和类