Stay Hungry,Stay Foolish!

A. One and Two

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;
}
 

 

posted @ 2023-02-11 11:04  lightsong  阅读(19)  评论(0编辑  收藏  举报
Life Is Short, We Need Ship To Travel