hdu5744(16多校第2场,思维题)
来源:互联网 发布:马云大数据时代演讲 编辑:程序博客网 时间:2024/06/04 19:27
Keep On Movin
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1454 Accepted Submission(s): 694
Problem Description
Professor Zhang has kinds of characters and the quantity of thei -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 <stdio.h>#define ll long longusing namespace std;int main(){ int T,n,a; while(~scanf("%d",&T)) { while(T--) { ll sum=0,num=0; int flag=0; scanf("%d",&n); for(int i=0; i<n; i++) { scanf("%d",&a); if(a%2==0) sum+=(ll)a; else num++,sum+=(ll)(a-1),flag=1; } if(flag==1) { ll ans=sum/(num*2); printf("%I64d\n",ans*2+1); } else printf("%I64d\n",sum); } } return 0;}
0 0
- hdu5744(16多校第2场,思维题)
- (多校第二场1011)HDU5744 Keep On Movin
- HDU5744(贪心)
- hdu5762(2016多校第三场,思维题)
- (hdu6075) 2017杭电多校联赛第四场-Questionnaire 思维题
- Codeforces Round #143 (Div. 2) (ABCD 思维场)
- hdu5744 多校2.11
- HDU5744 Keep On Movin
- hdu5744简单模拟
- 2017多校第3场 HDU 6058 Kanade's sum 双链表,思维
- 2017多校第3场 HDU 6060 RXD and dividing 思维,构造最优解
- 2015多校第7场 HDU 5371 Segment Game 思维,Manacher算法
- 2015多校第7场 HDU 5372 Segment Game 树状数组,思维
- 2017多校第4场 HDU 6073 Matching In Multiplication 拓扑排序,思维,DFS
- Hybrid Crystals (2017多校 第八场) (思维题 视力题)
- 2015多校联合第十场 hdu5414CRB and String字符串思维题
- 2017多校第二场 HDU 6052 To my boyfriend 思维,计数题
- 2017多校第一场 HDU 6038 Function 循环节,脑洞,大思维题
- ACM--递推加大数--HDOJ 1865--1string--水
- java生成EXCEL表单简单demo (未测试)
- Java对各种排序算法的实现(未测试)
- sharepoint 2016 学习系列篇(21)-文档库应用篇-(3)在文档库中上传文档和下载文档
- Hibernate中,One2Many和Many2One的双向映射关系的基于注解Annotation实现方式
- hdu5744(16多校第2场,思维题)
- Java正则表达式验证工具类(未测试)
- Android 6.0 telephony 联系人信息显示流程
- 二维码的生成和解码Java实现(未测试)
- GitHub Xcode 上传时出现的问题
- 关于内存管理和寻址、地址空间
- 金额大写转小写SQL(未测试)
- 【BZOJ 2301】Problem B 莫比乌斯反演
- eclipse创建一个Android应用工程产生的问题汇总