Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- #include <string>
- #include <cmath>
- #include <queue>
- #include <algorithm>
- #include <random>
- using namespace std;
- int mas[12][12];
- int k;
- struct Point {
- int x, y;
- };
- vector<Point> fir, sec;
- vector<pair<int, int> > go_to = {{1, 1}, {1, 0}, {1, -1}, {0, 1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}};
- Point best_start, best_go, best_shot;
- int prior = -1;
- bool can_go(Point p) {
- int x = p.x, y = p.y;
- if (!mas[x - 1][y - 1] || !mas[x - 1][y] || !mas[x - 1][y + 1]
- || !mas[x][y + 1] || !mas[x][y - 1]
- || !mas[x + 1][y - 1] || !mas[x + 1][y] || !mas[x + 1][y + 1])
- return true;
- return false;
- }
- void try_shot(Point p, int xx, int yy) {
- int pri = 0;
- for (int i = 0; i < 8; ++i)
- if (mas[p.x + go_to[i].first][p.y + go_to[i].second] == -1)
- pri++;
- for (int i = 0; i < 8; ++i) {
- int addx = go_to[i].first, addy = go_to[i].second, pr = pri;
- int x = xx + addx, y = yy + addy;
- while (!mas[x][y]) {
- for (int j = 0; j < 8; ++j) {
- if (mas[x + go_to[j].first][y + go_to[j].second] == 1)
- pr--;
- if (mas[x + go_to[j].first][y + go_to[j].second] == 2) {
- pr++;
- int temp = 0;
- for (int k = 0; k < 8; ++k) {
- if (mas[x + go_to[j].first + go_to[k].first][y + go_to[j].second + go_to[k].second]) {
- pr++;
- temp++;
- }
- }
- if (temp == 7)
- pr += 100000;
- }
- }
- if (pr > prior) {
- best_start.x = p.x - 1;
- best_start.y = p.y - 1;
- best_go.x = xx - 1;
- best_go.y = yy - 1;
- best_shot.x = x - 1;
- best_shot.y = y - 1;
- prior = pr;
- }
- x += addx;
- y += addy;
- }
- }
- }
- void try_go(Point p) {
- mas[p.x][p.y] = 0;
- for (int i = 0; i < 8; ++i) {
- int addx = go_to[i].first, addy = go_to[i].second;
- int x = p.x + addx, y = p.y + addy;
- while (!mas[x][y]) {
- mas[x][y] = 1;
- try_shot(p, x, y);
- mas[x][y] = 0;
- x += addx;
- y += addy;
- }
- }
- mas[p.x][p.y] = 1;
- }
- int main() {
- for (int i = 0; i < 12; ++i)
- for (int j = 0; j < 12; ++j)
- mas[i][j] = -1;
- for (int i = 1; i <= 10; ++i)
- for (int j = 1; j <= 10; ++j)
- cin >> mas[i][j];
- cin >> k;
- if (k == 2) {
- for (int i = 1; i <= 10; ++i) {
- for (int j = 1; j <= 10; ++j) {
- if (mas[i][j] == 1)
- mas[i][j] = 2;
- if (mas[i][j] == 2)
- mas[i][j] = 1;
- }
- }
- }
- for (int i = 1; i <= 10; ++i) {
- for (int j = 1; j <= 10; ++j) {
- if (mas[i][j] == 1) {
- Point temp;
- temp.x = i;
- temp.y = j;
- fir.push_back(temp);
- }
- if (mas[i][j] == 2) {
- Point temp;
- temp.x = i;
- temp.y = j;
- sec.push_back(temp);
- }
- }
- }
- for (int i = 0; i < 4; ++i) {
- if (can_go(fir[i]))
- try_go(fir[i]);
- }
- cout << best_start.x << " " << best_start.y << "\n";
- cout << best_go.x << " " << best_go.y << "\n";
- cout << best_shot.x << " " << best_shot.y << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement