Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)

这篇博客介绍了三道编程竞赛题目。第一题是寻找数组中和为偶数的子集,可以简单通过检查是否存在偶数来解决。第二题要求计算二元数组中由1组成的特定大小子矩形数量,关键在于连续1的因子。第三题涉及修复括号序列使其成为正确序列,通过重新排列子序列实现。
摘要由CSDN通过智能技术生成

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 t test 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 a.
The second line contains n integers a1,a2,…,an (1≤ai≤100), elements of a. The given array a can contain equal values (duplicates).

Output

For each test case output −1 if 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

Note

There are three test cases in the example.
In the first test case, you can choose the subset consisting of only the second element. Its sum is 4 and it is even.
In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.
In the third test case, the subset consisting of all array’s elements has even sum.

题意:有n个元素的数组,要求选出k个数字,使这k个数字之和为偶数。

思路:签到题。如果数组中存在偶数,直接选一个偶数即可,如果全是奇数,并且元素个数大于1,任意选择两个数即可,反之不存在,输出-1。

#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))

int s[110];

int main()
{
   
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;
    cin >> t;
    while(t--){
   
        int n;
        cin >> n;
        for(int i = 1; i <= n; i++) cin >> s[i];
        int flag = 0;
        for(int i = 1; i <= n; i++){
   
            if(s[i]%2==0){
   
                cout << 1 << endl;
                cout << i << endl;
                flag = 1;
                break;
            }
        }
        if(flag) continue;
        if(n<2
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值