Keep On Movin HDU
来源:互联网 发布:php 上传txt 编辑:程序博客网 时间:2024/05/29 10:40
Keep On Movin
HDU - 5744Professor Zhang has kinds of characters and the quantity of the
For example, there are 4 kinds of characters denoted as 'a', 'b', 'c', 'd' and the quantity of each character is
. 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.
Note that a string is called palindromic if it can be read the same way in either direction.
The first line contains an integer
441 1 2 432 2 251 1 1 1 151 1 2 2 3
3613
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int t;int sum,odd,n,k;int main(){ int i; scanf("%d",&t); while(t--){ sum = 0; odd = 0; scanf("%d",&n); for(i = 1; i <= n; i++){ scanf("%d",&k); if(k%2==0){ sum += k; } else{ sum += k-1; odd++; } } if(odd==0)printf("%d\n",sum); else printf("%d\n",sum/2/odd*2+1);//这是最关键的一句,sum是总的偶数的个数sum/2就是能分成多少组去填充奇数字符串,每一个实际上代表左右两边整体 //sum/2/odd代表这用这些组去填充这些个奇数串每个奇数串可以得到多少组去填充,sum/2/odd*2就像刚才说的sum/2的时候实际上是一个整体,代表了两边,所以实际 //长度要乘2才是填充上的长度,最后加1就是加的原本字符串的那一个字符,最后就是总的长度 } return 0;}
阅读全文
0 0
- 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
- 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 (字符串)
- java 构造函数 成员函数初始化顺序 以及多态的构造函数的调用顺序
- nginx的五种负载算法模式
- FMI飞马网【线上直播】持续集成在京东研发的落地及应用
- Java的内存机制
- Android Studio:xxx is not an enclosing class
- Keep On Movin HDU
- jquery.page创建分页
- jquery设置My97DatePicker日期选择插件只能以今天为起点。
- Linux集群配置SSH互信
- textAngular 文本编辑器的用法
- SPFA详解
- oracle操作数据库命令
- 九、java多态的理解
- 进程与线程