2016 Multi-University Training Contest 2 Keep On Movin
来源:互联网 发布:mac合盖屏幕亮 编辑:程序博客网 时间:2024/06/10 07:48
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
Author
zimpha
如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了.
#include<iostream>
#include<cstdio>
using namespace std;
int a[100005];
int main()
{
int t,n;
cin>>t;
while(t--)
{
cin>>n;
int sum=0,odd=0,num=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
sum+=a[i];
if(a[i]%2)
{
odd++;
num+=(a[i]-1)/2;
}
else
{
num+=a[i]/2;
}
}
if(odd==0)
printf("%d\n",sum);
else
{
printf("%d\n",1+2*(num/odd));
}
}
return 0;
}
0 0
- 2016 Multi-University Training Contest 2 Keep On Movin
- 2016 Multi-University Training Contest 2 1011 Keep On Movin
- 2016 Multi-University Training Contest 2 1011 Keep On Movin
- 2016 Multi-University Training Contest 2 Keep On Movin
- 2016 Multi-University Training Contest 2 -Keep On Movin
- 2016 Multi-University Training Contest 2 HDU 5744 Keep On Movin
- 2016 Multi-University Training Contest 2 1011 Keep On Movin (简单数学)
- HDU 5744 Keep On Movin// 2016 Multi-University Training Contest 2
- hdu 5744 Keep On Movin(2016 Multi-University Training Contest 2——回文串,思维题)
- (HDU 5744)Keep On Movin <回文数,思维水题> 2016 Multi-University Training Contest 2
- 【HDU5744 2016 Multi-University Training Contest 2K】【水题 贪心】Keep On Movin 给定字符使得最短回文串最长
- HDOJ 5744 (2016多校联合训练 Training Contest 2) Keep On Movin
- 2016 Multi-University Training Contest 2 Acperience
- 2016 Multi-University Training Contest 2
- 2016 Multi-University Training Contest 2 Acperience
- 2016 Multi-University Training Contest 2 Acperience
- 2016 Multi-University Training Contest 2 Eureka
- 2016 Multi-University Training Contest 2
- POJ2431 探险 解题报告
- JNI学习积累之一 ---- 常用函数大全
- PathMeasure之迷径追踪
- struts2学习笔记(一)
- 关于phpcms栏目列表从N条开始调用数据的问题
- 2016 Multi-University Training Contest 2 Keep On Movin
- ZABBIX中出现的Zabbix BUS discoverer processes 75%解疑
- Spark Transformation —— flatMap算子
- 分享css 填坑常用代码(未测试)
- run loop 再次理解和总结
- 介绍Windows/Linux下Oracle数据库进程如何启动和关闭
- 获取页面、屏幕、div宽度
- win10下tomcat9配置http2.0笔记
- 设计模式(十一) 外观模式(门面模式)