Codeforces Round #626 Div. 2 A - Even Subset Sum Problem

一、内容

 You are given an array a consisting of n positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 2) or determine that there is no such subset. Both the given array and required subset may contain equal values.

Input

The first line contains a single integer t(1≤t≤100), number of test cases to solve. Descriptions of ttest cases follow.A description of each test case consists of two lines. The first line contains a single integer n(1≤n≤100), length of array aThe second line contains nintegers a1,a2,…,an (1≤ai≤100), elements of a. The given array a can contain equal values (duplicates).

Output

For each test case output −1if there is no such subset of elements. Otherwise output positive integer k, number of elements in the required subset. Then output k distinct integers (1≤pi≤n ), indexes of the chosen elements. If there are multiple solutions output any of them.

Example
Input

3
3
1 4 3
1
15
2
3 5

Output

1
2
-1
2
1 2

二、思路

  • 找一个偶数 或者 2个奇数

三、代码

#include <cstdio>
#include <cstring>
using namespace std;
int t, n, num;
int main() {
	scanf("%d", &t);
	while (t--) {
		int a = 0, b = 0, c = 0;
		scanf("%d", &n);
		for (int i = 1; i <= n; i++) {
			scanf("%d", &num);
			if (num % 2 == 0) a = i;
			else if (!b) b = i;
			else if (!c) c = i; 
		} 
		if (a) printf("1\n%d\n", a);
		else if (b && c) printf("2\n%d %d\n", b, c);
		else printf("-1\n");
	}
	return 0;
} 
发布了512 篇原创文章 · 获赞 538 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/qq_41280600/article/details/104748567