A - 签到题1

You are given a sequence �1,�2,…,��a1​,a2​,…,an​. Each element of �a is 11 or 22.

Find out if an integer �k exists so that the following conditions are met.

  • 1≤�≤�−11≤kn−1, and
  • �1⋅�2⋅…⋅��=��+1⋅��+2⋅…⋅��a1​⋅a2​⋅…⋅ak​=ak+1​⋅ak+2​⋅…⋅an​.

If there exist multiple �k that satisfy the given condition, print the smallest.

Input

Each test contains multiple test cases. The first line contains the number of test cases �t (1≤�≤1001≤t≤100). Description of the test cases follows.

The first line of each test case contains one integer �n (2≤�≤10002≤n≤1000).

The second line of each test case contains �n integers �1,�2,…,��a1​,a2​,…,an​ (1≤��≤21≤ai​≤2).

Output

For each test case, if there is no such �k, print −1−1.

Otherwise, print the smallest possible �k.

Sample 1

InputcopyOutputcopy
3
6
2 2 1 2 1 2
3
1 2 1
4
1 1 1 1
2
-1
1

Note

For the first test case, �=2k=2 satisfies the condition since �1⋅�2=�3⋅�4⋅�5⋅�6=4a1​⋅a2​=a3​⋅a4​⋅a5​⋅a6​=4. �=3k=3 also satisfies the given condition, but the smallest should be printed.

For the second test case, there is no �k that satisfies �1⋅�2⋅…⋅��=��+1⋅��+2⋅…⋅��a1​⋅a2​⋅…⋅ak​=ak+1​⋅ak+2​⋅…⋅an

For the third test case, �=1k=1, 22, and 33 satisfy the given condition, so the answer is 11.

题解:
1:确定2的个数是奇数还是偶数。

2:如果为偶数,从左到右寻找2的个数,当为总的2的个数的一半时,记录此时i的数字

3:奇数的话就直接输出-1.

代码:

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c[10009];
    int n,d;
    cin>>n;
    while(n--)
    {
        cin>>b;
        int ct=0;
        for(int i=0;i<b;i++)
        {
            cin>>c[i];
            if(c[i]%2==0) ct++;
        }
        if(ct%2==0)
        {
            if(ct==0) cout<<"1"<<endl;
            else{d=ct/2;
            for(int i=0;i<b;i++)
            {
                if(c[i]%2==0) d--;
                if(d==0) {cout<<i+1<<endl;break;}
            }}
        }
        else cout<<"-1"<<endl;
    }
}

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值