CF1790D.Matryoshkas
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Matryoshka is a wooden toy in the form of a painted doll, inside which you can put a similar doll of a smaller size.
A set of nesting dolls contains one or more nesting dolls, their sizes are consecutive positive integers. Thus, a set of nesting dolls is described by two numbers: s — the size of a smallest nesting doll in a set and m — the number of dolls in a set. In other words, the set contains sizes of s,s+1,…,s+m−1 for some integer s and m (s,m>0).
You had one or more sets of nesting dolls. Recently, you found that someone mixed all your sets in one and recorded a sequence of doll sizes — integers a1,a2,…,an.
You do not remember how many sets you had, so you want to find the minimum number of sets that you could initially have.
For example, if a given sequence is a=[2,2,3,4,3,1]. Initially, there could be 2 sets:
- the first set consisting of 4 nesting dolls with sizes [1,2,3,4];
- a second set consisting of 2 nesting dolls with sizes [2,3].
According to a given sequence of sizes of nesting dolls a1,a2,…,an, determine the minimum number of nesting dolls that can make this sequence.
Each set is completely used, so all its nesting dolls are used. Each element of a given sequence must correspond to exactly one doll from some set.
套娃是一种木制玩具,外形为一个彩绘玩偶,其内部可嵌套一个尺寸更小的相似玩偶。
一套套娃包含一个或多个嵌套玩偶,它们的尺寸为连续的正整数。因此,一套套娃由两个数描述:s —— 该套中最小玩偶的尺寸,以及 m —— 该套中玩偶的总数。换言之,该套包含尺寸为 s,s+1,…,s+m−1 的玩偶(其中 s,m 为正整数)。
你原本拥有一套或多套这样的套娃。最近,你发现有人将你所有的套娃全部混在一起,并记录下了一串玩偶尺寸序列 —— 整数 a1,a2,…,an。
你不记得自己原先有多少套套娃,因此希望找出最初可能拥有的最少套数。
例如,若给定序列为 a=[2,2,3,4,3,1],则最初可能仅有 2 套:
- 第一套包含 4 个套娃,尺寸为 [1,2,3,4];
- 第二套包含 2 个套娃,尺寸为 [2,3]。
根据给定的套娃尺寸序列 a1,a2,…,an,确定能构成该序列的最少套娃套数。
每套必须被完全使用,即该套中所有玩偶均需出现在序列中;序列中的每个元素必须恰好对应某一套中一个玩偶。
输入格式
The first line of input data contains a single integer t (1≤t≤104) — the number of test cases.
The description of the test cases follows.
The first line of each test case contains one integer n (1≤n≤2⋅105) — the total number of matryoshkas that were in all sets.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the sizes of the matryoshkas.
It is guaranteed that the sum of values of n over all test cases does not exceed 2⋅105.
输入数据的第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 所有套娃集合中套娃的总数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 各套娃的尺寸。
保证所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, print one integer k — the minimum possible number of matryoshkas sets.
对于每个测试用例,输出一个整数 k —— 即套娃集合的最少可能数量。
输入输出样例
输入#1
10 6 2 2 3 4 3 1 5 11 8 7 10 9 6 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 8 1 1 4 4 2 3 2 3 6 1 2 3 2 3 4 7 10 11 11 12 12 13 13 7 8 8 9 9 10 10 11 8 4 14 5 15 6 16 7 17 8 5 15 6 14 8 12 9 11 5 4 2 2 3 4
输出#1
2 1 6 2 2 2 2 2 4 3
说明/提示
The first test case is described in the problem statement.
In the second test case, all matryoshkas could be part of the same set with minimum size s=7.
In the third test case, each matryoshka represents a separate set.
第一个测试用例已在题目描述中给出。
在第二个测试用例中,所有套娃均可组成一个集合,其最小尺寸为 s=7。
在第三个测试用例中,每个套娃各自构成一个独立的集合。
输入解题思路,AI测评打分。不知道怎么写?