博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu5744——Keep On Movin(构造回文)
阅读量:2343 次
发布时间:2019-05-10

本文共 1562 字,大约阅读时间需要 5 分钟。

Problem Description

Professor Zhang has kinds of characters and the quantity of the -th character is . 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 . 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 – the number of kinds of characters. The second line contains integers .

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

真是菜的不行,这种题都想了半天。反正就是把偶数个数的字符平均分到奇数(由于奇数能转化为1+偶数,所以在中间的基本上可以看做一个奇数)个字符的两边,C++除法的特性能够得出长度最小的那个

#include 
#include
#include
#include
#include
#include
#include
#include
#include
#define INF 0x3f3f3f3f#define MAXN 1010#define mod 1000000007using namespace std;int main(){ int t,n; scanf("%d",&t); while(t--) { int odd=0,even=0,m; scanf("%d",&n); for(int i=0;i
even) printf("1\n"); else { int ans=even/odd; printf("%d\n",ans*2+1); } } } return 0;}

转载地址:http://wscvb.baihongyu.com/

你可能感兴趣的文章
spring 简述
查看>>
HttpClient-03Http状态管理
查看>>
spring cloud 启动报错-must be declared as an @AliasFor [serviceId], not [name].
查看>>
常用软件下载地址
查看>>
修改spring boot 启动logo
查看>>
spring boot-启动及配置文件
查看>>
HttpsURLConnection 安全传输(HTTPS--Secure Hypertext Transfer Protocol-安全超文本传输协议)...
查看>>
ASP.NET跨页面传值的技巧
查看>>
ASP.NET页面之间传递值解析
查看>>
我要学ASP.NET MVC 3.0(八): MVC 3.0 传递和保存你的Model
查看>>
我要学ASP.NET MVC 3.0(九): MVC 3.0 验证你的Model
查看>>
我要学ASP.NET MVC 3.0(十): MVC 3.0 使用 Forms身份验证
查看>>
我要学ASP.NET MVC 3.0(十一): MVC 3.0 使用筛选器
查看>>
ASP.NET MVC3、Pager 分页
查看>>
在 ASP.NET MVC 中创建自定义 HtmlHelper 控件
查看>>
MSDN---扩展方法 (C# 方法中的this参数)
查看>>
我要学ASP.NET MVC 3.0(十四): MVC 3.0 实例系列之创建数据表格
查看>>
我要学ASP.NET MVC 3.0(十五): MVC 3.0 实例系列之表格的排序
查看>>
我要学ASP.NET MVC 3.0(十七): MVC 3.0 实例之表格中数据的筛选
查看>>
Displaying a Sorted, Paged, and Filtered Grid of Data in ASP.NET MVC
查看>>