CF1926D.Vlad and Division
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vladislav has n non-negative integers, and he wants to divide all of them into several groups so that in any group, any pair of numbers does not have matching bit values among bits from 1-st to 31-st bit (i.e., considering the 31 least significant bits of the binary representation).
For an integer k, let k2(i) denote the i-th bit in its binary representation (from right to left, indexing from 1). For example, if k=43, since 43=1010112, then 432(1)=1, 432(2)=1, 432(3)=0, 432(4)=1, 432(5)=0, 432(6)=1, 432(7)=0, 432(8)=0,…,432(31)=0.
Formally, for any two numbers x and y in the same group, the condition x2(i)=y2(i) must hold for all 1≤i<32.
What is the minimum number of groups Vlad needs to achieve his goal? Each number must fall into exactly one group.
弗拉迪斯拉夫有 n 个非负整数,他希望将所有这些数划分为若干组,使得在任意一组中,任意两个数在二进制表示的第 1 位至第 31 位(即最低的 31 个二进制位)上均无相同的比特值。
对任意整数 k,记 k2(i) 表示其二进制表示中从右向左数第 i 位的值(位索引从 1 开始)。例如,若 k=43,由于 43=1010112,则有 432(1)=1,432(2)=1,432(3)=0,432(4)=1,432(5)=0,432(6)=1,432(7)=0,432(8)=0,…,432(31)=0。
形式化地说,对同一组内的任意两个数 x 和 y,必须满足:对所有 1≤i<32,均有 x2(i)=y2(i)。
为达成目标,弗拉迪斯拉夫最少需要多少个组?每个数必须且仅能属于一个组。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤2⋅105) — the total number of integers.
The second line of each test case contains n given integers a1,…,an (0≤aj<231).
The sum of n over all test cases in a test does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)——测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)——整数的总个数。
每个测试用例的第二行包含 n 个给定的整数 a1,…,an(0≤aj<231)。
所有测试用例中的 n 之和不超过 2⋅105。
输出格式
For each test case, output a single integer — the minimum number of groups required to satisfy the condition.
对于每个测试用例,输出一个整数——满足条件所需的最少组数。
输入输出样例
输入#1
9 4 1 4 3 4 2 0 2147483647 5 476319172 261956880 2136179468 1671164475 1885526767 3 1335890506 811593141 1128223362 4 688873446 627404104 1520079543 1458610201 4 61545621 2085938026 1269342732 1430258575 4 0 0 2147483647 2147483647 3 0 0 2147483647 8 1858058912 289424735 1858058912 2024818580 1858058912 289424735 122665067 289424735
输出#1
4 1 3 2 2 3 2 2 4
说明/提示
In the first test case, any two numbers have the same last 31 bits, so we need to place each number in its own group.
In the second test case, a1=00000000000000000000000000000002, a2=11111111111111111111111111111112 so they can be placed in the same group because a1(i)=a2(i) for each i between 1 and 31, inclusive.
在第一个测试用例中,任意两个数的最低 31 位都相同,因此我们需要将每个数单独分到一个组中。
在第二个测试用例中,a1=00000000000000000000000000000002,a2=11111111111111111111111111111112,因此它们可以被分到同一组中,因为对每个 i(1≤i≤31),均有 a1(i)=a2(i)。
输入解题思路,AI测评打分。不知道怎么写?