[CF2160A]A - MEX Partition题解

time limit per test

1 second

memory limit per test

256 megabytes

Let a partition of a multiset B be a collection of multisets s1,s2,…,sk such that each element appears the same number of times in B and across all of s1,s2,…,sk.

For example, some partitions of {1,2,3,3} include {1,3}+{2,3},{1,2,3,3}, and {2}+{1,3}+{3}, but not {1,2}+{3}.

A partition is called valid if the mex∗ of all multisets in the partition is the same. The score of a valid partition is the mex of any multiset in the partition.

You are given a multiset A of size n. Find the minimum score over all valid partitions of A.

∗The minimum excluded (MEX) of a collection of integers c1,c2,…,ck is defined as the smallest non-negative integer x which does not occur in the collection c.

有道 翻译

设一个多集 B 的分区是一个多集 s1,s2,…,sk 的集合,使得每个元素在 B 和所有 s1,s2,…,sk 中出现的次数相同。

例如, {1,2,3,3} 的一些分区包括 {1,3}+{2,3},{1,2,3,3} 和 {2}+{1,3}+{3} ,但不包括 {1,2}+{3} 。

如果分区中所有multiset的 mex ∗ 相同,则该分区称为valid。有效分区的分数是分区中任何多集的 mex 。

你得到一个大小为 n 的多集 A 。找出 A 的所有有效分区的最小分数。

∗ 整数集合 c1,c2,…,ck 的最小排除(MEX)被定义为在集合 c 中不出现的最小非负整数 x 。

Input

Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100). The description of the test cases follows.

The first line of each test case contains an integer n (1≤n≤100).

The second line contains n integers A1,A2,…,An denoting the elements of A (0≤Ai≤100).

It is not guaranteed that the elements are given in non-decreasing order.

有道 翻译

输入** **

每个测试包含多个测试用例。第一行包含测试用例的数量 t ( 1≤t≤100 )。下面是测试用例的描述。

每个测试用例的第一行包含一个整数 n ( 1≤n≤100 )。

第二行包含 n 个整数 A1,A2,…,An ,表示 A ( 0≤Ai≤100 )的元素。

不能保证元素是按非递减顺序给出的。

Output

For each test case, output the minimum score over all valid partitions.

Example

Input

Copy



2

3

0 0 0

2

1 2

Output

Copy



1

0

Note

In the first test case, the minimum score of 1 can be obtained by the partition {0}+{0}+{0}. The partition is valid because each multiset has a mex of 1, which is consequently the score of the partition.

In the second test case, we can use {1,2} as the only multiset in the partition, which has mex0.

思路

直接模拟。

代码见下

#include<bits/stdc++.h>
using namespace std;
long long t,n,a[105],b[105];
int main(){
	cin>>t;
	while(t--){
		cin>>n;
		for(int i=0;i<=100;i++){
			b[i]=0;
		}
		for(int i=1;i<=n;i++){
			cin>>a[i];
			b[a[i]]++;
		}
		for(int i=0;i<=n;i++){
			if(b[i]==0){
				cout<<i<<endl;
				break;
			}
		} 
//		if(b[0]==0){
//			cout<<0<<endl;
//		}
//		else{
//			cout<<1<<endl;
//		}
	}
    return 0;
}

posted @ 2025-10-13 09:39  bz02_2023f2  阅读(2)  评论(0)    收藏  举报  来源