You are on page 1of 3

#include <iostream>

#include <stdio.h>
using namespace std;
struct Coord {
int x;
int y;
Coord () {
x = 0;
y = 0;
}
Coord (int inX, int inY) {
x = inX;
y = inY;
}
};
int Height, Width;
char Board [1000][1000];
Coord Dragons[1000000];
Coord Exit;
Coord Entry;
int DragonTop;
bool valid;
void Draw (Coord Center, int Radius) {
for (int i = 0; i < Radius; i++) //TOP RIGHT
if (Center.x + i < Width && Center.y + Radius - i < Height)
if (Board [Center.x + i][Center.y + Radius - i] != '*')
Board [Center.x + i][Center.y + Radius - i] = 'X';
for (int i = 0; i < Radius; i++) //BOTTOM RIGHT
if (Center.x + Radius - i < Width && Center.y - i >= 0)
if (Board [Center.x + Radius - i][Center.y - i] != '*')
Board [Center.x + Radius - i][Center.y - i] = 'X';
for (int i = 0; i < Radius; i++) //BOTTOM LEFT
if (Center.x - i >= 0 && Center.y - Radius + i >= 0)
if (Board [Center.x - i][Center.y - Radius + i] != '*')
Board [Center.x - i][Center.y - Radius + i] = 'X';
for (int i = 0; i < Radius; i++) //TOP LEFT
if (Center.x - Radius + i >= 0 && Center.y + i < Height)
if (Board [Center.x - Radius + i][Center.y + i] != '*')
Board [Center.x - Radius + i][Center.y + i] = 'X';
}
void ClearBoard() {
for (int i = 0; i < Height; i++)
for (int k = 0; k < Width; k++)
if (Board [i][k] == 'X' || Board[i][k] == 'P')
Board[i][k] = '.';
}
void ShowBorder() {
for (int i = 0; i < Height; i++) {
for (int k = 0; k < Width; k++)
cout << Board [i][k];
cout << '\n';
}
}
void Lee(Coord pos) {
if (!valid) {
if (pos.x == Exit.x && pos.y == Exit.y) {
valid = true;
return;
}
if (Board [pos.x][pos.y] == '.') {
Board [pos.x][pos.y] = 'P';
if (pos.x + 1 < Width) {
char cobai = Board[pos.x + 1][pos.y];
if (cobai != 'P' && cobai != 'X' && cobai != '*')
Lee (Coord(pos.x + 1, pos.y));
}
if (pos.x - 1 >= 0) {
char cobai = Board[pos.x - 1][pos.y];
if (cobai != 'P' && cobai != 'X' && cobai != '*')
Lee (Coord(pos.x - 1, pos.y));
}
if (pos.y + 1 < Height) {
char cobai = Board[pos.x][pos.y + 1];
if (cobai != 'P' && cobai != 'X' && cobai != '*')
Lee (Coord(pos.x, pos.y + 1));
}
if (pos.y - 1 >= 0) {
char cobai = Board[pos.x][pos.y - 1];
if (cobai != 'P' && cobai != 'X' && cobai != '*')
Lee (Coord(pos.x, pos.y - 1));
}
}
}
}
int main() {
freopen("barbar.in", "r", stdin);
//freopen("barbar.out", "w", stdout);
cin >> Height >> Width;
for (int i = 0; i < Height; i++)
for (int k = 0; k < Width; k++) {
cin >> Board[i][k];
if (Board[i][k] == 'D') {
Dragons[DragonTop++] = Coord(i, k);
Board[i][k] = 'X';
}
if (Board[i][k] == 'I')
Entry = Coord (i, k);
if (Board[i][k] == 'O')
Exit = Coord (i, k);
}
for (int k = 0; k < DragonTop; k++)
Draw (Dragons[k], 2);
return 0;
int CurrentLevel = 10;
int lvl;
for (int i = 1; i <= CurrentLevel; i++) {
valid = false;
for (int k = 0; k < DragonTop; k++)
Draw (Dragons[k], i);
Lee(Entry);
if (valid)
lvl = i;
ClearBoard();
}
cout << lvl;
return 0;
for (int i = 0; i < Height; i++) {
for (int k = 0; k < Width; k++)
cout << Board[i][k] << " ";
cout << '\n';
}
}