当前位置:网站首页>B. All Distinct
B. All Distinct
2022-07-04 03:52:00 【Felven】
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Sho has an array aa consisting of nn integers. An operation consists of choosing two distinct indices ii and jj and removing aiai and ajaj from the array.
For example, for the array [2,3,4,2,5][2,3,4,2,5], Sho can choose to remove indices 11 and 33. After this operation, the array becomes [3,2,5][3,2,5]. Note that after any operation, the length of the array is reduced by two.
After he made some operations, Sho has an array that has only distinct elements. In addition, he made operations such that the resulting array is the longest possible.
More formally, the array after Sho has made his operations respects these criteria:
- No pairs such that (i<ji<j) and ai=ajai=aj exist.
- The length of aa is maximized.
Output the length of the final array.
Input
The first line contains a single integer tt (1≤t≤1031≤t≤103) — the number of test cases.
The first line of each test case contains a single integer nn (1≤n≤501≤n≤50) — the length of the array.
The second line of each test case contains nn integers aiai (1≤ai≤1041≤ai≤104) — the elements of the array.
Output
For each test case, output a single integer — the length of the final array. Remember that in the final array, all elements are different, and its length is maximum.
Example
input
Copy
4 6 2 2 2 3 3 3 5 9 1 9 9 1 4 15 16 16 15 4 10 100 1000 10000
output
Copy
2 1 2 4
Note
For the first test case Sho can perform operations as follows:
- Choose indices 11 and 55 to remove. The array becomes [2,2,2,3,3,3]→[2,2,3,3][2,2,2,3,3,3]→[2,2,3,3].
- Choose indices 11 and 44 to remove. The array becomes [2,2,3,3]→[2,3][2,2,3,3]→[2,3].
The final array has a length of 22, so the answer is 22. It can be proven that Sho cannot obtain an array with a longer length.
For the second test case Sho can perform operations as follows:
- Choose indices 33 and 44 to remove. The array becomes [9,1,9,9,1]→[9,1,1][9,1,9,9,1]→[9,1,1].
- Choose indices 11 and 33 to remove. The array becomes [9,1,1]→[1][9,1,1]→[1].
The final array has a length of 11, so the answer is 11. It can be proven that Sho cannot obtain an array with a longer length.
解题说明:此题统计出相同数字出现的个数,然后判断相同的个数是否为2的整数倍,如果是就直接去除,否则要多去除1个数。
#include<stdio.h>
int main()
{
int t, n, i, b;
scanf("%d", &t);
while (t--)
{
int c = 0;
int a[100000] = { 0 };
scanf("%d", &n);
for (i = 0; i<n; i++)
{
scanf("%d", &b);
if (a[b])
{
c++;
}
else
{
a[b] = 1;
}
}
if (c % 2 == 0)
{
printf("%d\n", n - c);
}
else
{
printf("%d\n", n - c - 1);
}
}
return 0;
}边栏推荐
- Ppt tutorial, how to save a presentation as a PDF file in PowerPoint?
- (指针)编写函数void fun(int x,int *pp,int *n)
- 统计遗传学:第三章,群体遗传
- JS realizes the effect of text scrolling marquee
- 毕业设计:设计秒杀电商系统
- Pointer array and array pointer
- 【微服务|openfeign】@FeignClient详解
- 苹果CMS仿西瓜视频大气响应式视频模板源码
- 软件测试是干什么的 发现缺陷错误,提高软件的质量
- R语言中如何查看已安装的R包
猜你喜欢

leetcode刷题:二叉树04(二叉树的层序遍历)
TCP-三次握手和四次挥手简单理解

What does software testing do? Find defects and improve the quality of software

leetcode刷题:二叉树06(对称二叉树)

Flink learning 6: programming model

Emlog user registration plug-in is worth 80 yuan

架构训练毕业设计+总结

User defined path and file name of Baidu editor in laravel admin

Boutique website navigation theme whole station source code WordPress template adaptive mobile terminal

02 ls 命令的具体实现
随机推荐
JS realizes the effect of text scrolling marquee
96% of the collected traffic is prevented by bubble mart of cloud hosting
批处理初识
毕业设计项目
一个漂亮的API文档生成工具
MIN_RTO 对话
西部数据绿盘、蓝盘、黑盘、红盘和紫盘有什么区别
tdk-lambda电源主要应用
Common methods of threads
Brief explanation of depth first search (with basic questions)
什么是上下文?
Msgraphmailbag - search only driveitems of file types
Parameterization of controls in katalon
资深开发人员告诉你,怎样编写出优秀的代码?
Flink学习7:应用程序结构
RPC技术
Configuration and hot update of nocturnal simulator in hbuildx
02 ls 命令的具体实现
The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO
TCP-三次握手和四次挥手简单理解