B. GCD Compression

Ashish has an array a of consisting of 2n positive integers. He wants to compress a into an array b of size n−1. To do this, he first discards exactly 2 (any two) elements from a. He then performs the following operation until there are no elements left in a:

Remove any two elements from a and append their sum to b.
The compressed array b has to have a special property. The greatest common divisor (gcd) of all its elements should be greater than 1.

Recall that the gcd of an array of positive integers is the biggest integer that is a divisor of all integers in the array.

It can be proven that it is always possible to compress array a into an array b of size n−1 such that gcd(b1,b2…,bn−1)>1.

Help Ashish find a way to do so.

Input
The first line contains a single integer t (1≤t≤10) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (2≤n≤1000).

The second line of each test case contains 2n integers a1,a2,…,a2n (1≤ai≤1000) — the elements of the array a.

Output
For each test case, output n−1 lines — the operations performed to compress the array a to the array b. The initial discard of the two elements is not an operation, you don’t need to output anything about it.

The i-th line should contain two integers, the indices (1 —based) of the two elements from the array a that are used in the i-th operation. All 2n−2 indices should be distinct integers from 1 to 2n.

You don’t need to output two initially discarded elements from a.

If there are multiple answers, you can find any.

Example
inputCopy
3
3
1 2 3 4 5 6
2
5 7 9 10
5
1 3 3 4 5 90 100 101 2 3
outputCopy
3 6
4 5
3 4
1 9
2 3
4 5
6 10
Note
In the first test case, b={3+6,4+5}={9,9} and gcd(9,9)=9.

In the second test case, b={9+10}={19} and gcd(19)=19.

In the third test case, b={1+2,3+3,4+5,90+3}={3,6,9,93} and gcd(3,6,9,93)=3.

题意
有一个长度为2n的数组a,第一步要先在a数组中去掉2个数(任意),然后剩下的数中,每次选任意两个(不能重复选),求出选中的两个数的和,把它们加到数组b中,反复处理,直到a数组没有数。保证b数组最后所有数的最大公约数>1,输出每一次选的两个数的下标
思路
最大公约数>1,我们能不能保证最大公约数=2呢,是可以的,只要我们构造的数组b全为偶数
因为数组a的长度为偶数,所以有以下两种情况

  1. 数组a中有偶数个偶数,偶数个奇数
  2. 数组a中有奇数个偶数,奇数个奇数

对于情况1,有以下2种操作

  1. 去掉2个偶数,那么奇数和奇数构造,偶数和偶数构造,相加为偶数,保证了b数组中的数都为偶数
  2. 去掉2个奇数,同理

对于情况2,我们只有一种操作

  1. 去掉1个奇数,1个偶数。数组中的奇数和偶数都变为偶数个了,那么奇数和奇数构造,偶数和偶数构造
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
//#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int odd[2020];
int even[2020];
int n, m;
int a[2020];
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		cin >> n ;
		int cnt_odd = 0, cnt_even = 0;
		for (int i = 1; i <= 2 * n; i++)
		{
			cin >> a[i];
			if (a[i] % 2) odd[++cnt_odd] = i;
			else even[++cnt_even] = i;
		}
		if (cnt_odd % 2 == 0) //情况1
		{
			if (cnt_odd >= 2) //操作1
			{
				for (int i = 4; i <= cnt_odd; i+=2) cout << odd[i - 1] << " " << odd[i] << endl;
				for (int i = 2; i <= cnt_even; i+=2) cout << even[i - 1] << " " << even[i] << endl;
			}
			else  //操作2
			{
				for (int i = 2; i <= cnt_odd; i+=2) cout << odd[i - 1] << " " << odd[i] << endl;
				for (int i = 4; i <= cnt_even; i+=2) cout << even[i - 1] << " " << even[i] << endl;
			}
		}
		else //情况2
		{
			for (int i = 3; i <= cnt_odd; i+=2) cout << odd[i - 1] << " " << odd[i] << endl;
			for (int i = 3; i <= cnt_even; i+=2) cout << even[i - 1] << " " << even[i] << endl;
		}

	}

}
system.io.compression是.NET Framework中用于文件压缩和解压缩的命名空间。它提供了一组类和方法,用于处理不同类型的压缩算法和压缩文件。 在system.io.compression命名空间中,最常用的类是GZipStream和DeflateStream。这两个类可以实现对文件和流进行gzip和deflate压缩。GZipStream可以将数据压缩成gzip格式,而DeflateStream可以将数据压缩成deflate格式。 使用这些类,我们可以轻松地将文件或数据进行压缩。首先,我们创建一个压缩流对象,然后将输入流传递给该对象。接下来,我们可以使用Write方法将数据写入压缩流中。最后,我们可以使用Flush和Close方法来完成压缩操作,并将压缩后的数据保存到文件或另一个流中。 除了压缩,system.io.compression还提供了对压缩文件的解压缩的功能。例如,我们可以使用GZipStream和DeflateStream类的Read方法,从压缩文件中读取数据,并使用解压缩流对象将数据解压缩。 在实际应用中,system.io.compression可以用于压缩和解压缩文件以减少存储空间和网络传输带宽的占用。它在一些需要处理大量数据且对存储和传输效率有要求的应用场景中非常有用,例如大型文件传输、数据备份和归档等。 总而言之,system.io.compression提供了一组实用的类和方法,使我们能够轻松地实现对文件和数据的压缩和解压缩操作。它是.NET Framework中非常实用和重要的命名空间之一。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值