#include #include #include #include #include using namespace std; const int MAXN = 11; int m[MAXN][MAXN], hitted[MAXN][MAXN], sum = 17, lx, ly, lastHit, curx, cury; set > s; bool func (int x, int y, int dir, int siz) { if (dir == 0) { for (int i = 0; i < siz; ++i) if (m[x + i][y]) return 0; } else if (dir == 1) { for (int i = 0; i < siz; ++i) if (m[x][y + i]) return 0; } if (dir == 0) { for (int i = 0; i < siz; ++i) m[x + i][y] = 1; } else if (dir == 1) { for (int i = 0; i < siz; ++i) m[x][y + i] = 1; } return 1; } void pune (int siz) { int x, y, dir; while (1) { dir = rand() % 2; x = rand() % 10 + 1; y = rand() % 10 + 1; if (func (x, y, dir, siz)) { cout << x << " " << y << " " << (dir + 1) % 2 << "\n"; break; } } } bool get_respond() { string a; getline(cin, a); if (a[0] == 'H') { lx = curx; ly = cury; lastHit = 1; } else if (a[0] == 'S') lastHit = 0; if (a[0] == 'W') return 1; return 0; } bool randomHit() { int poz = rand() % s.size(); set >::iterator it = s.begin(); for (int i = 1; i <= poz; ++it, ++i); cout << (*it).first << " " << (*it).second << "\n"; curx = (*it).first; cury = (*it).second; cout.flush(); s.erase(it); return get_respond(); } int abs (int a) { if (a < 0) return -a; return a; } bool sHit(int x, int y) { set > nS; set >::iterator it = s.begin(); for (it = s.begin(); it != s.end(); ++it) { int nx = (*it).first; int ny = (*it).second; if (abs(nx - x) + abs(ny - y) <= 1) nS.insert (make_pair(nx, ny)); } int poz = rand() % nS.size(); it = nS.begin(); for (int i = 0; i <= poz; ++i, ++it); cout << (*it).first << " " << (*it).second << "\n"; int nx = (*it).first; int ny = (*it).second; for(it = s.begin(); it != s.end(); ++it) if ((*it).first == nx && (*it).second == ny) { s.erase(it); break; } curx = nx; cury = ny; cout.flush(); return get_respond(); } int main() { //freopen("d.in", "r", stdin); srand(time(0)); pune(2); pune(3); pune(3); pune(4); pune(5); cout.flush(); for (int i = 1; i <= 10; ++i) for (int j = 1; j <= 10; ++j) s.insert(make_pair(i, j)); while (1) { if (lastHit) { if (sHit(lx, ly)) return 0; } else if (randomHit()) return 0; cout.flush(); int x, y; cin >> x >> y; if (m[x][y]) { m[x][y] = 0; --sum; } if (sum == 0) return 0; } return 0; }