Keep On Movin
来源:互联网 发布:java开源网盘系统 编辑:程序博客网 时间:2024/06/05 21:00
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} 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) . Output For each test case, output an integer denoting the answer. Sample Input Sample Output
For example, there are 4 kinds of characters denoted as 'a', 'b', 'c', 'd' and the quantity of each character is
. 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.
Note that a string is called palindromic if it can be read the same way in either direction.
The first line contains an integer
441 1 2 432 2 251 1 1 1 151 1 2 2 3
3613
题意说的可能比较模糊,所以我尽量再来解释一遍。说的就是“He also wants to maximize the length of the shortest palindromic string.”,他不是要改变这个最短的长度,他只是想要找到所有的分组情况中,最短的那个字符串,然后再从这些短的字符串中找到最长的长度。所以我们能直接加到最长最好,只有一个串,自然就是最长。可是如果有两个串的话,我们怎么办呢? 比如 1 1 2 2,我们必须创建两个串,这样才能用掉所有的字符。也就是以奇数在中间。我们要最长,所以我们应该尽量的使所有的串最长,这样的话,才能使该组中最短的最长,剩下的就是除了奇数,奇数我们变为1+偶数,这样的话,我们就可以用多余的字符,再来平均。
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int maxn=1e5+10;int val[maxn];int main(){ int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); int odd_num=0; int sum_even=0; for(int i=1;i<=n;i++) { scanf("%d",&val[i]); int temp=val[i]; if(temp%2) { odd_num++; sum_even += (temp-1); continue; } sum_even += temp; } if(!odd_num) { printf("%d\n",sum_even); continue; } while((sum_even/odd_num)%2!=0) { sum_even -= 2; } printf("%d\n",sum_even/odd_num+1); } return 0;}
阅读全文
0 0
- Keep On Movin
- HDU Keep On Movin
- Keep On Movin
- HDU5744 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
- hdu 5744 Keep On Movin
- hdu 5744 Keep On Movin
- 多校2.Keep On Movin
- HDU 5744 ( Keep On Movin )
- HDU 5744 Keep On Movin
- HDU 5744 Keep On Movin
- 【HDU】5744 Keep On Movin
- vs2010项目属性配置
- 挑战程序竞赛系列(36):3.3线段树和平方分割
- 分享阿里云云服务器优惠
- Linux系统下的根文件系统与挂载探究
- 你值得拥有的Apsara Clouder云计算专项技能认证:云存储-对象存储管理与安全
- Keep On Movin
- 搜索我文章的访问(csdn搜索自己博客的办法)
- 面试题
- 百度之星之路径交
- C++调用结构体
- LinearLayout权重布局
- c++实现卷积过程
- 剑指offer(4)—重建二叉树
- 如何快速的有序的对多层级结构的代码进行分类管理