VJ F - I am bored

Being a judge is not always an interesting job! For example, it is very boring to wait for the first submission in the contest. So, judges used to entertain themselves using the “I’m Bored” tab in the PC 2 software. In this tab, a button is shown and you need to click it (if you can!).

Since Alaa has been a judge in many contests, the “I’m Bored” tab is also boring to her, so, she decided to play a new game in today’s contest. Alaa brings with her a huge bag full of lowercase English letters, and she starts playing with them. Alaa goal is to build a list of palindrome strings of the same length such that each string does not contain the same character more than two times.

After 3 minutes of playing, Alaa wondered what is the longest string’s length that she can build? And what is the maximum number of strings the list can contain? When Alaa brings her notebook to calculate the answers, she starts receiving dozens of submissions. So, she gives you her bag and asks you to find the answers for her. Can you?

Input
The first line contains an integer T (1 ≤ T ≤ 104) specifying the number of test cases.

Each test cases consists of a line containing 26 integers f 1, …, f 26 (0 ≤ f i ≤ 109), in which f i is how many letters i Alaa has. The letters are numbered from 1 to 26 starting from ‘a’.

Output
For each test case, print a single line containing two integers x and y, in which x is the length of the strings in the group and y is the size of the group.

Example
Input
2
2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Output
4 1
4 2
题意:分别输入拥有的26个字母的个数,求这些字母能组成最长回文串的长度和最长回文串的个数(每个字母的数量最多为2)(我认为题目这里表述部署很清楚)因为也可以理解成能最多能组成回文串的数量(不一定最长)。
分析:如果有字母数量超过或者等于2,那么该字母一定会在最长的回文串里对称出现,最长回文串长度加2,如果有字母数量是1那么它可以成为最长回文串的中间的一个字母。此时最长回文串长度加一(只能加一次)。(如果全为1,最长回文串长度就是1并且最多的数量就等于数量等于1的字母的个数,这一点很重要,我做的时候忽略了这一点),还有要注意所有数量都为0的情况代码中是否可以体现(开始我的代码就没有体现导致多次wa,-_ -,😅。
代码:
#include
#include <bits/stdc++.h>
using namespace std;

int main()
{
int t;
scanf("%d",&t);
while(t–)
{
int a[30];
int num=0, num2[30], cnt = 0;
memset(num2,0,sizeof(num2));//保证如果所有字母数量为0时,结果正确
int flag = 0;
for(int i = 1;i<=26;i++)
{
scanf("%d",&a[i]);
if(a[i]>=2)
{
num+=2;
num2[cnt++]=a[i]/2;//保存长度超过二的字母最多可以在几个回文串里出现)
}
else if(a[i]==1)
flag++;//(保存数量为一的字母的个数)
}
sort(num2,num2+cnt);
int minn = 100000000;//最多组成多少回文串
if(flag > 0)
{
num++;//如果存在数量为一的字母,最长回文串长度加一
minn = min(flag,num2[0]);//(如果回文串中同时有数量为2和数量为一的字母,此时回文串的数量受这两个方面的限制,且数量为两者中的最小值)
}
else
{

       minn = num2[0];//(如果没有数量为一的字母,回文串的数量只受数量为2的字母的限制)
    }
    if(num==1)//如果只有数量为一的字母
     printf("%d %d\n",num,flag);
     else
        printf("%d %d\n",num,minn);
}
return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值