/* -*- coding: utf-8 -*- * * 355.cc: No.355 数当てゲーム(2) - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int N = 4; const int PN = 24; // =4! /* typedef */ typedef vector vi; /* global variables */ int cs[10]; vi pns[PN]; /* subroutines */ void ask(vi &ds, int &h, int &b) { for (int i = 0; i < N; i++) { if (i) putchar(' '); printf("%d", ds[i]); } putchar('\n'); cout.flush(); cin >> h >> b; if (h == N) exit (0); } int check(vi &ds) { int h, b, n; vi dps(N), hcs(N); bool first = true; for (int i = 0; i < PN; i++) { vi &pni = pns[i]; for (int j = 0; j < N; j++) dps[j] = ds[pni[j]]; ask(dps, h, b); n = h + b; if (h == n) { if (first) { for (int j = 0; j < N; j++) hcs[j] = dps[j]; first = false; } else for (int j = 0; j < N; j++) if (hcs[j] != dps[j]) hcs[j] = -1; } } if (n == 3) { int x = 0; for (int i = 0; i < N && x == ds[i]; i++, x++); for (int i = 0; i < N; i++) { int tmp = hcs[i]; hcs[i] = x; ask(hcs, h, b); if (h == 3) { hcs[i] = -1; break; } hcs[i] = tmp; } } for (int j = 0; j < N; j++) if (hcs[j] >= 0) cs[hcs[j]] = j; //for (int j = 0; j < N; j++) printf("%d ", hcs[j]); putchar('\n'); return n; } /* main */ int main() { vi pn(N); for (int i = 0; i < N; i++) pn[i] = i; for (int i = 0; i < PN; i++) { pns[i] = pn; next_permutation(pn.begin(), pn.end()); } memset(cs, -1, sizeof(cs)); vi ds(N); for (int i = 0; i < N; i++) ds[i] = i; int n0 = check(ds); for (int i = 0; i < N; i++) ds[i] = i + 4; int n1 = check(ds); for (int i = 0; i < N; i++) ds[i] = i + 6; int n2 = check(ds); for (int i = 0; i < 10; i++) if (cs[i] >= 0) ds[cs[i]] = i; int h, b; ask(ds, h, b); return 0; }