当前位置:网站首页>B. All Distinct
B. All Distinct
2022-07-04 04:31: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.
Problem solving instructions : This question counts the number of the same number , Then judge whether the same number is 2 Integer multiple , If so, remove it directly , Otherwise, remove more 1 Number .
#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;
}
边栏推荐
- Virtual commodity account trading platform source code_ Support personal QR code collection
- Application scheme of Puyuan ds1000z series digital oscilloscope in communication principle experiment
- Unity Resource path
- leetcode刷题:二叉树04(二叉树的层序遍历)
- leetcode刷题:二叉树09(二叉树的最小深度)
- Tcp- simple understanding of three handshakes and four waves
- RPC技术
- R语言dplyr中的Select函数变量列名
- UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0x98 in position 1093: illegal multibyte sequence
- 【微服务|openfeign】@FeignClient详解
猜你喜欢
Redis:有序集合zset类型数据操作命令
leetcode:1314. 矩阵区域和【二维前缀和模板】
资深开发人员告诉你,怎样编写出优秀的代码?
Flink learning 6: programming model
Redis: order collection Zset type data operation command
【微服务|openfeign】@FeignClient详解
架构训练毕业设计+总结
ModStartBlog 现代化个人博客系统 v5.2.0 源码下载
博朗与Virgil Abloh于2021年为纪念博朗品牌100周年而联合打造的“功能性艺术”将在博物馆展出Abloh作品期间首次亮相
苹果CMS仿西瓜视频大气响应式视频模板源码
随机推荐
Main applications of TDK lambda power supply
分布式系统:what、why、how
Architecture training graduation design + summary
leetcode刷题:二叉树08(N叉树的最大深度)
EIG在智利推出可再生能源平台Grupo Cerro
Talking about what a high-quality little red book copy needs to have
RHCSA 08 - automount配置
RHCSA 01 - 创建分区与文件系统
两万字带你掌握多线程
VIM add interval annotation correctly
【微服务|openfeign】@FeignClient详解
西部数据绿盘、蓝盘、黑盘、红盘和紫盘有什么区别
分布式CAP理论
[microservice openfeign] @feignclient detailed explanation
Imitation of "game bird" source code, mobile game issue evaluation, open service, open test collection, game download website template
leetcode 121 Best Time to Buy and Sell Stock 买卖股票的最佳时机(简单)
ctf-pikachu-XSS
Select function variable column name in dplyr of R language
R语言dplyr中的Select函数变量列名
Redis: operation command for collecting set type data