int map[5][5], delx[5], dely[5]; voidclear(){ ms(delx, 0); ms(dely, 0); for (int i = 1; i <= 4; i++) { int flag = 1; for (int j = 1; j <= 4; j++) if (map[i][j] == 0) flag = 0; if (flag) delx[i] = 1; } for (int i = 1; i <= 4; i++) { int flag = 1; for (int j = 1; j <= 4; j++) if (map[j][i] == 0) flag = 0; if (flag) dely[i] = 1; } for (int i = 1; i <= 4; i++) { if (delx[i]) for (int j = 1; j <= 4; j++) map[i][j] = 0; if (dely[i]) for (int j = 1; j <= 4; j++) map[j][i] = 0; } }
intmain(){ scanf("%s", s); n = strlen(s); for (int i = 0; i < n; i++) { if (s[i] == '0') { for (int i = 1; i <= 4; i++) { if (map[1][i] == 0 && map[2][i] == 0) { map[1][i] = map[2][i] = 1; printf("1 %d\n", i); break; } elseif (map[3][i] == 0 && map[4][i] == 0) { map[3][i] = map[4][i] = 1; printf("3 %d\n", i); break; } } } elseif (s[i] == '1') { for (int i = 1; i <= 4; i++) { if (map[i][3] == 0 && map[i][4] == 0) { map[i][3] = map[i][4] = 1; printf("%d 3\n", i); break; } } } clear(); } return0; }
string s; intquery(int a, int b){ cout << "? " << a << " " << b << endl; char s[5]; cin >> s; return s[0] - 'x'; }
// 1 % a, 2 % a, 4 % a, ... , 2^n % a
intmain(){ ios::sync_with_stdio(false); cin.tie(0); while (cin >> s) { if (s == "end" || s == "mistake") break; int mx = 30; for (int i = 1; i <= 29; i++) { int x = query(1 << (i - 1), 1 << i); if (x == 0) { mx = i; break; } } // cout << "ha " << mx << endl; int l = 1 << (mx - 1), r = (1 << mx) + 1; while (l < r) { int m = (l + r) >> 1; // cout << m << ' ' << l << ' ' << r << endl; if (query(r, m) == 1) l = m + 1; else r = m; } cout << "! " << r << endl; } return0; }