Keep On Movin
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1607 Accepted Submission(s): 1036
Problem Description
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 {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.
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 n (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 n (1≤n≤105) -- the number of kinds of characters. The second line contains n integers a1,a2,...,an (0≤ai≤104).
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
Author
zimpha
Source
Recommend
思路:
每一个奇数都可以分解为1+偶数,然后就很简单了这道题
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include<queue>
#include<vector>
#include<string>
#include<iostream>
using namespace std;
#define Max 3000100
#define MOD 530600414
typedef long long LL;
int t,n,m;
int main()
{
cin>>t;
while(t--)
{
int ans=0,cnt=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
int temp;
scanf("%d",&temp);
if(temp%2)
ans+=temp/2,cnt++;
else
ans+=temp/2;
}
if(cnt==0)
cout<<ans*2<<endl;
else if(ans<cnt)
cout<<1<<endl;
else
cout<<ans/cnt*2+1<<endl;
}
return 0;
}