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; }
出处:http://www.cnblogs.com/lightsong/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。