Created
October 24, 2015 15:55
-
-
Save asi1024/a89049ca79b2d0dd9103 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define REP(i,n) for(int i=0;i<(int)(n);++i) | |
using namespace std; | |
int N; | |
char t[256][256]; | |
vector<int> edge(int v, int prev) { | |
vector<int> res; | |
REP(i,N) if (t[v][i] == '@' && i != prev) res.push_back(i); | |
return res; | |
} | |
int main() { | |
while (cin >> N, N) { | |
REP(i,N) REP(j,N) t[i][j] = 'o'; | |
REP(i,N) t[i][i] = '#'; | |
REP(i,N-1) t[i][i+1] = '@'; | |
t[2][N-2] = '@'; | |
REP(i,N) { | |
REP(j,i+1) cout << t[j][N-i+j-1]; | |
cout << endl; | |
} | |
REP(i,N) REP(j,i+1) { | |
char c; cin >> c; | |
t[j][N-i+j-1] = c; | |
t[N-i+j-1][j] = c; | |
} | |
int v1 = -1, v2 = -1, v3 = -1; | |
REP(i,N) { | |
vector<int> es = edge(i, i); | |
if (es.size() == 1) { | |
vector<int> es2 = edge(es[0], i); | |
if (es2.size() == 2) v3 = es[0]; | |
if (es2.size() == 1) { v1 = i; v2 = es2[0]; } | |
} | |
} | |
t[v2][v3] = 'o'; t[v3][v2] = 'o'; | |
int prev = edge(v1, v1)[0]; | |
vector<int> res(N); | |
res[v1] = 1; res[prev] = 2; res[v2] = 3; | |
REP(i,N-3) { | |
int n = edge(v2, prev)[0]; | |
res[n] = i + 4; | |
prev = v2; v2 = n; | |
} | |
REP(i,N) { | |
if (i > 0) cout << " "; | |
cout << res[i]; | |
} | |
cout << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment