HDU 5744 Keep On Movin
来源:互联网 发布:七天网络网页版 编辑:程序博客网 时间:2024/06/05 12:42
2016暑期集训3-F
HDU 5744 Keep On Movin
想法题
传送门:HustOJ
传送门:HDU
题意
N种字母,每种a[i]个。用这些字母组成多个(可以是1个)回文串,但每个字母都要用。每种组合方案中最小长度的回文串的最大值是多少。
比如:
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.
思路
每种回文串想最长,一定是中间一个字母,然后依次往外对称分布字母。所以回文串的个数就是字母个数中奇数的个数,(如果没有奇数,那么偶数个的字幕一定能全拼一起组成一个回文串)。每读一种字母的个数,如果他是奇数,拆出一个1,剩下的拆成2,如果是偶数,那么全拆成2。最后看如果拆出1的个数是0,那么输出偶数个数乘2,这时所有字幕都是偶数个,可以组成一个长的回文串。否则最小长度就是(2*(ou/ji))+1,因为/是向下取整的。
代码
#include<cstdio>#include<algorithm>#include<cstdlib>#include<cstring>#include<cmath>using namespace std;int main ( ){ int n; scanf ( "%d" , &n ); while ( n-- ) { int m; scanf ( "%d" , &m ); int ji = 0 , ou = 0; for ( int i = 0; i < m; i++ ) { int temp; scanf ( "%d" , &temp ); if ( temp % 2 ) { ji++; ou += ( ( temp - 1 ) ) / 2; } else { ou += ( temp / 2 ); } } int ans = 1; if ( ji == 0 ) { printf ( "%d\n" , 2 * ou ); } else { ans += ( 2 * ( ou / ji ) ); printf ( "%d\n" , ans ); } } return 0;}
0 0
- 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
- hdu 5744 Keep On Movin
- HDU Keep On Movin
- Keep On Movin HDU
- Keep On Movin HDU
- 水题-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 (字符串)
- 【贪心】Codeforces698A-Vacations
- 杭电acm-------2502月之数
- GUI系列文章——GUI发展史
- spring中的Ioc技术是怎样实现解耦的
- 使用ContentProviderOperation 来提升应用性能
- HDU 5744 Keep On Movin
- 论文中的长句子
- Tree Preorder, Inorder, and Postorder Iteratively Summarization
- 记PHPStudy-win10系统80端口被占用的经历
- hdu5724 博弈+SG函数+状压 多校1
- scala parse使用记录
- hdoj 1014 Divding(03背包问题)
- 计算几何:极角排序(poj 2007 Scrambled Polygon)与简单凸包(poj 1113 Wall)
- 开源