首页 > 其他分享 >A. One and Two

A. One and Two

时间:2023-02-11 11:12:19浏览次数:31  
标签:1788 temp int Two cin twopos

A. One and Two

https://codeforces.com/problemset/problem/1788/A

思路

统计2的个数,

如果是奇数个, 不满足

如果是偶数个, 2队列中,前半部分最后一个2则为目标位置

如果个数是0, 即都是1的情况, 则k=1

Code

https://codeforces.com/problemset/submission/1788/193070452

int t;
 
int main()
{
    cin >> t;
 
    REP(i, t){
        int n;
        vector<int> a;
        vector<int> twopos;
        
        cin >> n;
        
        REP(j, n){
            int temp;
            cin >> temp;
            
            a.push_back(temp);
            
            if(temp == 2){
                twopos.push_back(j+1);
            }
        }
        
        int twopos_len = twopos.size();
        if(twopos_len % 2 == 1){
            cout << -1 << endl;
            continue;
        }
        
        if(twopos_len == 0){
            cout << 1 << endl;
            continue;
        }
        
        int mfpos = twopos[twopos_len/2-1];
 
        cout << mfpos << endl;
    }
 
 
    return 0;
}
 

 

标签:1788,temp,int,Two,cin,twopos
From: https://www.cnblogs.com/lightsong/p/17111060.html

相关文章