hdu-5744 Keep On Movin(思维) Keep On Movin

题目链接:

Time Limit: 4000/2000 MS (Java/Others)   

 Memory Limit: 65536/65536 K (Java/Others)


Problem Description
 
Professor Zhang has kinds of characters and the quantity of the 
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 integer ).
 
Output
 
For each test case, output an integer denoting the answer.
 
Sample Input
 
4
4
1 1 2 4
3
2 2 2
5
1 1 1 1 1
5
1 1 2 2 3
 
Sample Output
 
3
6
1
3
 
题意:
 
给出每种字符有多少个,现在要你全部用完,拼成回文串,问回文串最短的那串的最长长度是多少;
 
思路:
 
每俩个相同的字符就可以加在任意的串上,要使最短的最长,所以就要平均加;
具体的看代码吧;
 

 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('
');
}

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<<"
";
			else cout<<sum*2<<"
";
			//if(sum%num==0)cout<<1+sum/num*2<<endl;
			//else cout<<1+sum

		}
        return 0;
}