#include #include #include #include using namespace std; typedef vector col; typedef vector matrix; void add_permutation(matrix &m, int x1, int x2, int y1, int y2, int n) { x1 ++; x2 ++; y1 ++; y2 ++; if(y1 > y2) swap(y1, y2); col buf; for( int i = 1; i <= n; i++){ if( i != x1 && i != x2) buf.push_back(i); } buf.insert(buf.begin() + y1 - 1, x1); buf.insert(buf.begin() + y2 - 1, x2); m.push_back(buf); buf[y1 - 1] = x2; buf[y2 - 1] = x1; m.push_back(buf); } inline void invert(int & inv) { inv = 1 - inv; } int main(void) { int ncases; cin >> ncases; int n = ncases * 2 + 1; matrix isplus(n, col(n, 0)); char c; int nplus = 0; for( int y = 0; y < n; y++){ cin >> ws; for(int x = 0; x < n; x++){ cin >> c; isplus[x][y] = (c == '+'? 1:0); if(c=='+') nplus ++; } } matrix ret; while(nplus > 2 * ncases){ for(int x1 = 0; x1 < n; x1 ++){ for(int x2 = x1 + 1; x2 < n; x2++){ // merge col c(n); transform(isplus[x1].begin(), isplus[x1].end(), isplus[x2].begin(), c.begin(), plus()); int c_count = count(c.begin(), c.end(), 2); if( c_count >= 2){ col::iterator yit1, yit2; int y1, y2; yit1 = find(c.begin(), c.end(), 2); yit2 = find(yit1 + 1, c.end(), 2); y1 = yit1 - c.begin(); y2 = yit2 - c.begin(); add_permutation(ret, x1, x2, y1, y2, n); invert(isplus[x1][y1]); invert(isplus[x1][y2]); invert(isplus[x2][y1]); invert(isplus[x2][y2]); nplus -= 4; goto endloop; }else if( c_count == 1){ int c1_count = count(c.begin(), c.end(), 1); if(c1_count >= 1){ col::iterator yit1, yit2; int y1, y2; yit1 = find(c.begin(), c.end(), 2); yit2 = find(c.begin(), c.end(), 1); y1 = yit1 - c.begin(); y2 = yit2 - c.begin(); add_permutation(ret, x1, x2, y1, y2, n); invert(isplus[x1][y1]); invert(isplus[x1][y2]); invert(isplus[x2][y1]); invert(isplus[x2][y2]); nplus -= 2; goto endloop; }else{ // fail } }else{ // fail } } } // end conditiion cout << "No solution" << endl; return 0; endloop: ; } cout << "There is solution:" << endl; if(ret.size() == 0) { for(int i = 0; i < n; i++) cout << i + 1 << (i == n - 1? "":" "); cout << endl; for(int i = 0; i < n; i++) cout << i + 1 << (i == n - 1? "":" "); cout << endl; return 0; } for(int i = 0; i < ret.size(); i ++){ for(int j = 0; j < ret[i].size(); j++){ cout << ret[i][j] << (j == ret[i].size() - 1? "":" "); } cout << endl; } return 0; }