思路:
贪心乱搞。
实现:
1 #include <bits/stdc++.h> 2 using namespace std; 3 vector<vector<int>> v; 4 int main() 5 { 6 string s; 7 while (cin >> s) 8 { 9 set<int> x, y; 10 for (int i = 0; i < v.size(); i++) v[i].clear(); 11 bool no_ans = false; 12 for (int i = 0; i < s.length(); i++) 13 { 14 if (s[i] == ‘1‘) 15 { 16 if (x.empty()) { no_ans = true; break; } 17 auto be = x.begin(); 18 int tmp = *be; 19 x.erase(be); 20 v[tmp].push_back(i); 21 y.insert(tmp); 22 } 23 else 24 { 25 if (y.empty()) { v.push_back(vector<int>()); y.insert(v.size() - 1); } 26 auto be = y.begin(); 27 int tmp = *be; 28 y.erase(be); 29 v[tmp].push_back(i); 30 x.insert(tmp); 31 } 32 } 33 for (int i = 0; i < v.size(); i++) 34 { 35 if (v[i].size() && s[v[i].back()] == ‘1‘) no_ans = true; 36 } 37 if (no_ans) cout << -1 << endl; 38 else 39 { 40 cout << v.size() << endl; 41 for (int i = 0; i < v.size(); i++) 42 { 43 cout << v[i].size() << " "; 44 for (int j = 0; j < v[i].size(); j++) 45 { 46 cout << v[i][j] + 1 << " "; 47 } 48 cout << endl; 49 } 50 } 51 } 52 return 0; 53 }