B. M-arrays
B.M-阵列
time limit per test: 1 second
每次测试的时间限制:1秒
memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节
input: standard input
输入:标准输入
output: standard output
产出:标准产出
You are given an array a1, a2,…, an consisting of n positive integers and a positive integer m.
给你一个数组A1,a2,.,一个由n个正整数和一个正整数m组成的数组。
You should divide elements of this array into some arrays. You can order the elements in the new arrays as you want.
您应该将这个数组的元素划分为一些数组。您可以根据需要对新数组中的元素排序。
Let’s call an array m-divisible if for each two adjacent numbers in the array (two numbers on the positions i andi + 1 are called adjacent
如果对于数组中的每两个相邻数,我们调用一个m-可除的数组(i和di+1位置上的两个数字称为相邻的)。
for each i) their sum is divisible by m. An array of one element is m-divisible.
对于每个i),它们的和可被m整除。一个元素的数组是m-可除的。
Find the smallest number of m-divisible arrays that a1, a.,…, an is possible to divide into.
找到最小数目的m-可除数组,其中a1,a,.an是可以划分的。
Input
输入
The first line contains a single integert (1 < t≤1000)一the number of test cases.
第一行包含一个整数(1<t≤1000),一测试用例数。
The first line of each test case contains two integersn, m(1≤n≤10,1≤m≤105).
每个测试用例的第一行包含两个整数,m(1≤n≤10,1≤m≤105)。
The second line of each test case contains n integers a,a2,…,an(1≤qi≤109).
每个测试用例的第二行包含n个整数a,a2,.,an(1≤qi≤109)。
It is guaranteed that the sum of n and the sum of m over all test cases do not exceed 10.
保证所有测试用例的n和m和不超过10。
Output
输出量
For each test case print the answer to the problem.
对于每个测试用例,打印出问题的答案。
余数系统一组,分组时互补的记一个
int main()
{
int t, n, m, x;
cin>>t;
while (t--)
{
int sum = 0;
memset(a, 0, sizeof(a));
cin>>n>>m;
for (int i = 0; i < n; ++i)
{
cin>>x;
++a[x % m];
}
if (a[0] != 0)
++sum;
for (int i = 1; i <= m / 2; ++i)
{
if (a[i] == a[m - i]&&a[i])
++sum;
else
sum += abs(a[i] - a[m - i]);
}
cout<<sum<<endl;
}
return 0;
}