hdu-5744 Keep On Movin(思维)
题目链接:
Keep On Movin
Time Limit: 4000/2000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
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.
The first line contains an integer n (1≤n≤105) -- the number of kinds of characters. The second line contains n integers a1,a2,...,an (0≤ai≤104).
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <bits/stdc++.h>
#include <stack> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=1e9+7;
const double PI=acos(-1.0);
const int inf=1e9;
const int N=1e5+10;
const int maxn=500+10;
const double eps=1e-9; int a[N]; int main()
{
int t;
read(t);
while(t--)
{
int n,num=0,sum=0;
read(n);
For(i,1,n)
{
read(a[i]);
if(a[i]&1)num++;
sum+=a[i]/2;
}
if(num)cout<<1+sum/num*2<<"\n";
else cout<<sum*2<<"\n";
//if(sum%num==0)cout<<1+sum/num*2<<endl;
//else cout<<1+sum }
return 0;
}
hdu-5744 Keep On Movin(思维)的更多相关文章
- HDU 5744 Keep On Movin (贪心)
Keep On Movin 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5744 Description Professor Zhang has k ...
- HDU 5744 Keep On Movin 贪心
Keep On Movin 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5744 Description Professor Zhang has k ...
- HDU 5744 Keep On Movin
Keep On Movin Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- hdu 5744 Keep On Movin (2016多校第二场)
Keep On Movin Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tot ...
- HDU 5744 Keep On Movin (贪心) 2016杭电多校联合第二场
题目:传送门. 如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了. #include <iostream ...
- HDU 6187 Destroy Walls (思维,最大生成树)
HDU 6187 Destroy Walls (思维,最大生成树) Destroy Walls *Time Limit: 8000/4000 MS (Java/Others) Memory Limit ...
- 【HDU 5744】Keep On Movin
找出奇数个的数有几个,就分几组. #include<cstdio> #include<cstring> #include<algorithm> #include&l ...
- 2017多校第9场 HDU 6161 Big binary tree 思维,类似字典树
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6161 题意: 题目是给一棵完全二叉树,从上到下从左到右给每个节点标号,每个点有权值,初始权值为其标号, ...
- HDU 5538 House Building(模拟——思维)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5538 Problem Description Have you ever played the vi ...
- hdu 4747 mex 线段树+思维
http://acm.hdu.edu.cn/showproblem.php?pid=4747 题意: 我们定义mex(l,r)表示一个序列a[l]....a[r]中没有出现过得最小的非负整数, 然后我 ...
随机推荐
- iOS -- app全局字体设置
方法一: 写一个UILabel(FontExtension)扩展重写initWithFrame(手写代码必走方法)和awakeFromNib(xib必走方法)当然UIButton.UITextView ...
- Android 你应该注意的开发规范
本文由Blankj投稿. Blankjd的博客地址: http://www.jianshu.com/u/46702d5c6978 为了利于项目维护以及规范开发,促进成员之间Code Review的效率 ...
- SqlServer查询语句中用到的锁
前段时间**公司DBA来我们这培训.讲了一大堆MYSQL的优化. QA环节一程序员问“SQL语句中的 with nolock 除了不锁表外,是否能读其他锁住的数据". 讲课的人嘟嘟了半天没解 ...
- js 数组的迭代
es5新增加的迭代方法(every,filter,forEach,map,some) arr1 = [1,2,3,4,5,6]; 1,every(); every() 方法使用指定函数检测数组中的所有 ...
- python(6)- 常用快捷键及基础命令
- MySQL的timeout那点事
http://www.mysqlops.com/2011/11/24/mysql_timeout.html
- [单元測试]_[VC2010使用gtest单元測试入门]
场景: 1. gtest作为C++的单元測试工具非常优秀了,它集成了非常多标准assert所没有的功能,比方让流程继续运行的EXPECT,仅仅測试特定測试用例的--gtest_filter, 输出xm ...
- 2.Qt Creator的使用
下面以一个简单的程序来说明Qt Creator的使用: 首先,按图片步骤创建一个Qt项目 创建完成后 上图标记处工具栏提供了简化树形视图.分栏等功能(自行尝试吧...) 在使用Qt制作一个界面时,我们 ...
- 惊艳的cygwin——Windows下的Linux命令行环境的配置和使用
http://www.tuicool.com/articles/2MramqI 时间 2014-07-29 09:28:36 点滴之间 聚沙成金 原文 http://www.path8.net/t ...
- Java RESTful 框架
[转载] 最好的8个 Java RESTful 框架 - 2015 Top 8 Java RESTful Micro Frameworks – Pros/Cons - 2017 Restlet - f ...