#include <exception>
#include <ios>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
struct field_t {
field_t(int n, int m) : alive_cells_count(0), self_(n), m_(m) {
for (auto &i : self_) {
std::cin >> i;
for (const auto j : i)
if (j == 'X' || j == '#')
alive_cells_count++;
}
}
std::string fire(int target_n, std::string_view target_m) {
const auto [norm_n, norm_m] = to_normal_coords(target_n, target_m);
if (self_.at(norm_n).at(norm_m) == '#') {
self_.at(norm_n).at(norm_m) = 'X';
return "HIT";
}
else if (self_.at(norm_n).at(norm_m) == 'X') {
self_.at(norm_n).at(norm_m) = '$';
alive_cells_count--;
if (alive_cells_count == 0)
return "GAMEOVER";
if (has_neighbours(norm_n, norm_m))
return "HIT";
return "SUNK";
}
return "MISSED";
}
private:
std::vector<std::string> self_;
int alive_cells_count;
int m_;
std::pair<int, int> to_normal_coords(int n, std::string_view m) {
const int norm_n = -(n - self_.size());
auto m_last = m.back();
int norm_m = static_cast<int>(m_last - 'A');
if (m.size() == 2)
norm_m += 26;
return {norm_n, norm_m};
}
bool has_neighbours(int norm_n, int norm_m) {
for (int i = 1; norm_n + i < self_.size(); i++) {
const auto neighbour = self_.at(norm_n + i).at(norm_m);
if (neighbour == 'X' || neighbour == '#')
return true;
if (neighbour == '.')
break;
}
for (int i = 1; norm_n - i >= 0; i++) {
const auto neighbour = self_.at(norm_n - i).at(norm_m);
if (neighbour == 'X' || neighbour == '#')
return true;
if (neighbour == '.')
break;
}
for (int i = 1; norm_m + i < m_; i++) {
const auto neighbour = self_.at(norm_n).at(norm_m + i);
if (neighbour == 'X' || neighbour == '#')
return true;
if (neighbour == '.')
break;
}
for (int i = 1; norm_m - i >= 0; i++) {
const auto neighbour = self_.at(norm_n).at(norm_m - i);
if (neighbour == 'X' || neighbour == '#')
return true;
if (neighbour == '.')
break;
}
return false;
}
};
int main() {
int t = 0;
std::cin >> t;
for (; t; t--) {
int n = 0, m = 0, unused;
try {
std::cin >> n >> m >> unused >> unused;
field_t players[2]{{n, m},{n,m}};
int curr_player = 1;
int q;
std::cin >> q;
bool flag = true;
for (; q; q--) {
std::cin.ignore(5);
int target_n;
std::string target_m;
std::cin >> target_n >> target_m;
if (flag) {
auto res = players[curr_player].fire(target_n, target_m);
curr_player = curr_player == 1 ? 0 : 1;
if (res == "GAMEOVER") {
std::cout << "WIN " << curr_player + 1 << std::endl;
flag = false;
} else
std::cout << res << std::endl;
}
}
} catch (const std::exception &ex) {
std::cout << ex.what() << ' ' << n;
}
} #include <iostream>
constexpr int WHITE = 3, RED = 0, LVL_COUNT = 52, COLORS_COUNT = 4;
int main() {
int elka[LVL_COUNT][COLORS_COUNT] = {};
auto next_color = [current = -1]() mutable {
if (current == WHITE) {
current = RED;
return current;
}
return ++current;
};
for (std::size_t i = 0; i < LVL_COUNT; i++) {
for (std::size_t j = 0; j <= i; j++)
elka[i][next_color()]++;
}
int days_count = 0, lvls_with_white = 0;
for (std::size_t i = 0; i < LVL_COUNT; i++) {
while (elka[i][0] > 0 || elka[i][1] > 0 || elka[i][2] > 0) {
int max = 0;
for (std::size_t j = 0; j < COLORS_COUNT; j++) {
elka[i][j]--;
if (j != WHITE)
if (elka[i][j] > elka[i][max])
max = j;
}
elka[i][max] = 0;
days_count++;
}
if (elka[i][3] > 0)
lvls_with_white++;
}
std::cout << days_count << lvls_with_white;
}