当前位置:网站首页>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;
}
边栏推荐
- [Logitech] m720
- What does software testing do? Find defects and improve the quality of software
- Leetcode brush questions: binary tree 05 (flip binary tree)
- Boutique website navigation theme whole station source code WordPress template adaptive mobile terminal
- I.MX6U-ALPHA开发板(模仿STM32驱动开发实验)
- Katalon uses script to query list size
- Small record of thinking
- How to view installed r packages in R language
- Parameterization of controls in katalon
- Rhcsa 01 - create partitions and file systems
猜你喜欢
MySQL JDBC编程
ModStartBlog 现代化个人博客系统 v5.2.0 源码下载
Main applications of TDK lambda power supply
Graduation project: design seckill e-commerce system
Flink learning 7: application structure
Architecture training graduation design + summary
DP83848+网线热拔插
Keysight N9320B射频频谱分析仪解决轮胎压力监测方案
Redis: hash type data operation command
Understand the principle of bytecode enhancement technology through the jvm-sandbox source code
随机推荐
程序员远程办公喜忧参半| 社区征文
How to add custom API objects in kubernetes (1)
EIG在智利推出可再生能源平台Grupo Cerro
Boutique website navigation theme whole station source code WordPress template adaptive mobile terminal
(指针)自己写一个比较字符串大小的函数,功能与strcmp类似。
Katalon uses script to query list size
Why use node
Dry goods | detailed explanation of webshell Foundation
C语言单向链表练习
Keysight N9320B射频频谱分析仪解决轮胎压力监测方案
Rhcsa 04 - process management
Select function variable column name in dplyr of R language
ModStartBlog 现代化个人博客系统 v5.2.0 源码下载
Leetcode 121 best time to buy and sell stock (simple)
领导:谁再用redis过期监听实现关闭订单,立马滚蛋!
(pointer) write a function to compare the size of strings by yourself, which is similar to StrCmp.
【微服务|openfeign】feign的两种降级方式|Fallback|FallbackFactory
[microservice openfeign] @feignclient detailed explanation
Rhcsa 08 - automount configuration
Exercises in quantum mechanics