当前位置:网站首页>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;
}边栏推荐
- (pointeur) Écrivez - vous une fonction qui compare la taille de la chaîne et fonctionne comme strcmp.
- Distributed system: what, why, how
- Krypton saikr daily question - CTF
- R语言中如何查看已安装的R包
- Operation of ES6
- 毕业三年,远程半年 | 社区征文
- Pointer array and array pointer
- Leetcode skimming: binary tree 07 (maximum depth of binary tree)
- 01 qemu 启动编译好的镜像 VFS: Unable to mount root fs on unknown-block(0,0)
- leetcode刷题:二叉树05(翻转二叉树)
猜你喜欢

Modstartblog modern personal blog system v5.2.0 source code download

leetcode刷题:二叉树09(二叉树的最小深度)

Flink学习8:数据的一致性
![[Logitech] m720](/img/bb/44144a1c3907808398c05b3b36962c.png)
[Logitech] m720

DP83848+网线热拔插

Redis:哈希hash类型数据操作命令

The maximum expiration time of client secret in azure ad application registration is modified to 2 years

Brief explanation of depth first search (with basic questions)

量子力学习题

I.MX6U-ALPHA开发板(C语言版本LED驱动实验)
随机推荐
leetcode刷题:二叉树08(N叉树的最大深度)
透过JVM-SANDBOX源码,了解字节码增强技术原理
What does software testing do? Find defects and improve the quality of software
y55.第三章 Kubernetes从入门到精通 -- HPA控制器及metrics-server(二八)
Leetcode skimming: binary tree 09 (minimum depth of binary tree)
The three-year revenue is 3.531 billion, and this Jiangxi old watch is going to IPO
Configuration and hot update of nocturnal simulator in hbuildx
统计遗传学:第三章,群体遗传
Restore the subtlety of window position
Krypton saikr daily question - CTF
浅谈一篇优质的小红书文案需要具备什么
如何远程办公更有效率 | 社区征文
C language bidirectional linked list first edition
Interpretation of leveldb source code skiplist
领导:谁再用redis过期监听实现关闭订单,立马滚蛋!
ctf-pikachu-XSS
西部数据绿盘、蓝盘、黑盘、红盘和紫盘有什么区别
I.MX6U-ALPHA开发板(模仿STM32驱动开发实验)
02 specific implementation of LS command
仿《游戏鸟》源码 手游发号评测开服开测合集专区游戏下载网站模板