首页 > 其他 > 详细

Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)/CF1323 A. Even Subset Sum Problem(水题)

时间:2020-03-08 16:19:40      阅读:83      评论:0      收藏:0      [点我收藏+]

You are given an array aa consisting of nn positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by 22 ) 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 tt (1t1001≤t≤100 ), number of test cases to solve. Descriptions of tt test cases follow.

A description of each test case consists of two lines. The first line contains a single integer nn (1n1001≤n≤100 ), length of array aa .

The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai1001≤ai≤100 ), elements of aa . The given array aa can contain equal values (duplicates).

Output

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

Example
Input
Copy
3
3
1 4 3
1
15
2
3 5
Output
Copy
1
2
-1
2
1 2
利用奇数偶数性质就可以。
#include <bits/stdc++.h>
using namespace std;
int n,a[105];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int i,j;
        int ans=0,ans1=0,ans2=0,flag=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]%2==0)
            {
                flag=1;
                ans=i;
            }
            else
            {
                if(!ans1)
                {
                    ans1=i;
                }
                else if(!ans2)
                {
                    ans2=i;
                }
            }
        }
        if(flag)
        {
            cout<<1<<endl;
            cout<<ans<<endl;
            continue;
        }
        if(ans1&&ans2)
        {
            cout<<2<<endl;
            cout<<ans1<< <<ans2<<endl;
        }
        else
        {
            cout<<-1<<endl;
        }
    }
    return 0;
}

 

Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)/CF1323 A. Even Subset Sum Problem(水题)

原文:https://www.cnblogs.com/lipoicyclic/p/12442561.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!