HDOJ 5744 Keep On Movin(最大化最短回文串长度)
来源:互联网 发布:蛙5火箭知乎 编辑:程序博客网 时间:2024/06/05 22:49
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
一.总结与分析
做题时候最好先从感性上感觉一下,就会发现,奇数个的个数决定了最后会分成几个集合,然后为了最大化最小值只要先平分那几个偶数的就好了
//// main.cpp// Keep On Movin//// Created by 张嘉韬 on 16/7/21.// Copyright © 2016年 张嘉韬. All rights reserved.//#include <iostream>#include <cstring>#include <cstdio>using namespace std;int c1,c2,L;int main(int argc, const char * argv[]) { //freopen("/Users/zhangjiatao/Documents/暑期训练/input.txt","r",stdin); int T=0; cin>>T; for(int t=1;t<=T;t++) { int n=0; cin>>n; L=c1=c2=0; for(int i=1;i<=n;i++) { int temp=0; cin>>temp; if(temp%2!=0) c2++; c1+=temp/2; L+=temp; } if(c2==0) cout<<L<<endl; else { cout<<(c1/c2)*2+1<<endl; } } return 0;}
0 0
- HDOJ 5744 Keep On Movin(最大化最短回文串长度)
- HDOJ 5744 Keep On Movin(回文串)
- HDU-5744 Keep On Movin(回文串 贪心)
- HDOJ 5744 Keep On Movin
- 【HDU5744 2016 Multi-University Training Contest 2K】【水题 贪心】Keep On Movin 给定字符使得最短回文串最长
- hdu5744——Keep On Movin(构造回文)
- HDU 5744 Keep On Movin(水题)
- hdu 5744 Keep On Movin (字符串)
- HDU 5744 Keep On Movin(贪心)
- hdu 5744 Keep On Movin(2016 Multi-University Training Contest 2——回文串,思维题)
- hdu 5744 Keep On Movin
- hdu 5744 Keep On Movin
- hdu 5744 Keep On Movin
- hdu 5744 Keep On Movin
- HDU 5744 ( Keep On Movin )
- HDU 5744 Keep On Movin
- HDU 5744 Keep On Movin
- 【HDU】5744 Keep On Movin
- Android 补间动画
- SharedPreferences 监听变化Listener 的onSharedPreferenceChanged方法没有调用
- Iframe实现Ajax文件上传Servlet响应上传结果
- C#:网络通信(TCP)
- 第一章.对象导论之方法的重写和重载
- HDOJ 5744 Keep On Movin(最大化最短回文串长度)
- 使用新浪SAE平台的Storage存储,如何将存入的数据,下载到本地。爬坑之旅。
- mongodb_修改器($inc/$set/$unset/$push/$pop/upsert......)
- std::unique (去重)
- 欢迎使用CSDN-markdown编辑器
- 码神-day10-java
- 关于anaconda3下安装opencv3
- 用单链表实现大数相加,相乘
- Java网络编程学习笔记(二)流