2016 Multi-University Training Contest 2 Keep On Movin
2016-07-21 18:52
465 查看
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.
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
多校第二场水题。
题意:顺序地告诉你abcd….每一个都有几个 然后问你用他们去组成一系列的回文串,问怎么样才能使得这一系列回文串中最小的那一个的长度最大。
分析后可以发现如果说某一个字母的出现次数是偶数那么ok,他们是成对出现的,可以放在在同一个回文串中。但如果是奇数,我们就要拿出一个字母单独作为一个回文串(那么剩下的肯定是偶数个字母 就可以按偶数的情况讨论 ),同时我们发现,拿出的这些单独的字母他们必须各自组成一个回文串,比如样例a 1,b 1, c 2,d 4. 那么我们需要拿出一个a,一个b。那么剩下的所有字母都成对。这时候ab如果在一起怎么样也无法构成回文,所以只能分布在两个不同的串中,这时候我们知道至少要有两个串了,那么再将刚才统计好的 字母对 平均地分给他们,向下取整就是答案。
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.
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
多校第二场水题。
题意:顺序地告诉你abcd….每一个都有几个 然后问你用他们去组成一系列的回文串,问怎么样才能使得这一系列回文串中最小的那一个的长度最大。
分析后可以发现如果说某一个字母的出现次数是偶数那么ok,他们是成对出现的,可以放在在同一个回文串中。但如果是奇数,我们就要拿出一个字母单独作为一个回文串(那么剩下的肯定是偶数个字母 就可以按偶数的情况讨论 ),同时我们发现,拿出的这些单独的字母他们必须各自组成一个回文串,比如样例a 1,b 1, c 2,d 4. 那么我们需要拿出一个a,一个b。那么剩下的所有字母都成对。这时候ab如果在一起怎么样也无法构成回文,所以只能分布在两个不同的串中,这时候我们知道至少要有两个串了,那么再将刚才统计好的 字母对 平均地分给他们,向下取整就是答案。
#include "cstring" #include "cstdio" #include "iostream" #include "string.h" using namespace std; int main() { int cas; scanf("%d",&cas); while(cas--) { int n; int a[100005]; int sum=0; int dui=0; int odd=0; scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); sum+=a[i]; if(a[i]%2==1) { odd++; dui+=((a[i]-1)/2); } else dui+=a[i]/2; } if(odd!=0) printf("%d\n",1+2*(int)(dui/odd)); else printf("%d\n",sum); } }
相关文章推荐
- Gym 100646 You’ll be Working on the Railroad dfs
- 个人学习:main()函数
- 2016暑假多校合练第二场Multi-University Training Contest 2 1005 Eureka
- 2016 Multi-University Training Contest 2 Acperience(一直WA的小伙伴可以看看)
- [转自官方]2016 Multi-University Training Contest 2 solutions BY zimpha
- 2016 Multi-University Training Contest 2(2016多校训练第二场)1009
- grails无法从domian生成表
- AIX 创建文件系统
- leetcode 11.Container With Most Water
- Leetcode11 Container With Most Water
- [转] Linux 中/var/spool/postfix/maildrop目录下堆积大量小文件
- 2016 Multi-University Training Contest 2 1001 hdu 5734 暴力
- 2016 Multi-University Training Contest 2 1005 hdu 5738 计算几何
- 线程与信号
- BIO | NIO | AIO释疑
- AIO与BIO接口性能对比
- 2016 Multi-University Training Contest 1
- mac 命令行 Please try running this command again as root/Administrator
- (POJ1273)Drainage Ditches(裸最大流,EK模板)
- 2016 Multi-University Training Contest 2 Acperience