当前位置:网站首页>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;
}边栏推荐
- I Build a simple microservice project
- Evolution of MySQL database architecture
- 【微信小程序】好看的轮播图组件
- [microservice openfeign] use openfeign to remotely call the file upload interface
- [Logitech] m720
- The difference between bagging and boosting in machine learning
- 毕业设计:设计秒杀电商系统
- Modstartblog modern personal blog system v5.2.0 source code download
- RHCSA 07 - 用户与群组管理
- 精品网址导航主题整站源码 wordpress模板 自适应手机端
猜你喜欢

Two commonly used graphics can easily realize data display

Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file

2020 Bioinformatics | TransformerCPI

There is a problem that the package cannot be parsed in the like project

Emlog user registration plug-in is worth 80 yuan

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

苹果CMS仿西瓜视频大气响应式视频模板源码

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

Global exposure and roller shutter exposure of industrial cameras

Leetcode skimming: binary tree 04 (sequence traversal of binary tree)
随机推荐
程序员远程办公喜忧参半| 社区征文
RHCSA 01 - 创建分区与文件系统
Pytest基础自学系列(一)
(指针)自己写一个比较字符串大小的函数,功能与strcmp类似。
Tcp- simple understanding of three handshakes and four waves
Pytest basic self-study series (I)
Unity draws the trajectory of pinball and billiards
[csrf-01] basic principle and attack and defense of Cross Site Request Forgery vulnerability
【微服务|openfeign】feign的两种降级方式|Fallback|FallbackFactory
虚拟商品帐号交易平台源码_支持个人二维码收款
Two commonly used graphics can easily realize data display
Flink学习8:数据的一致性
Confession code collection, who says program apes don't understand romance
Leetcode brush questions: binary tree 05 (flip binary tree)
毕业设计:设计秒杀电商系统
仿《游戏鸟》源码 手游发号评测开服开测合集专区游戏下载网站模板
Asynchronous development process - touch your hand and lead you to realize a promise
Msgraphmailbag - search only driveitems of file types
陪驾注意事项 这23点要注意!
I was tortured by my colleague's null pointer for a long time, and finally learned how to deal with null pointer