版本比较
题解:P16795 [蓝桥杯 2026 国 B] 奇偶校验排列
正文
增加 44 行删除 37 行
12 行未改动131415161717181920212223242526272829303132333435363738394041424344454647192048222324252627282930313233343549505152533738395455565758594243444546474849505152535455606162636465575859666712 行未改动## 代码```cpp line-numbers#include<bits/stdc++.h>using namespace std;
int shao=0,yu=0,NBA=0;int n;string s;vector<int> O,E;vector<int> g(int st){ int co=0,ce=0; int now=st; if (now == 1) co++; else ce++;for(char c : s){ if(c == '1')now ^= 1; if (now == 1)co++; else ce++; } if(co != O.size() || ce != E.size()) return {}; vector<int> a; int p1=0,p2=0; now=st; if (now == 1) a.push_back(O[p1++]); else a.push_back(E[p2++]);for(char c : s){ if(c == '1')now ^= 1; if (now == 1) a.push_back(O[p1++]); else a.push_back(E[p2++]); } return a;}int main(){ int n,shao=0,yu=0,NBA=0; string s; cin >> n >> s; int t = 1; for(char c : s) if(c == '1') t ^= 1;
int co = 0, ce = 0; for(int i = 1; i <= n; ++i) if(i & 1) co++; else ce++;
int st = 1, ro = 1, re = 0; for(char c : s){ if(c == '1') st ^= 1; if(st) ro++; else re++;for(int i = 1; i <= n; i++){ if(i & 1) O.push_back(i); else E.push_back(i); }
if(ro != co or re != ce){ cout << -1; auto a = g(1); if(!a.empty()){for(int x : a) cout << x << " "; return 0; }
vector<int> O,E; for(int i = 1; i <= n; ++i) if(i & 1) O.push_back(i); else E.push_back(i);
vector<int> A; int p = 0, q = 0; A.push_back(O[p++]); st = 1; for(char c : s){ if(c == '1') st ^= 1; if(st) A.push_back(O[p++]); else A.push_back(E[q++]); a = g(0); if(!a.empty()){ for(int x : a) cout << x << " "; return 0; }
for(int x : A) cout << x << " "; return 0; cout << -1;}