Pagini recente » Cod sursa (job #935131) | Cod sursa (job #466616) | Cod sursa (job #214719) | Cod sursa (job #2455573) | Cod sursa (job #2110385)
#include <stdio.h>
#include <queue>
enum CellType
{
AIR = '.',
WALL = '*',
DRAGON = 'D',
START_POINT = 'I',
GATE = 'O'
};
struct Pos
{
int m_l, m_c;
Pos():m_l(0), m_c(0){}
Pos(int l, int c): m_l(l), m_c(c){}
};
const int MAX_N = 1000;
const int INF = MAX_N * MAX_N;
char map[MAX_N + 2][MAX_N + 2];
int distmap[MAX_N + 2][MAX_N + 2];
int memo[MAX_N + 2][MAX_N + 2];
int ldir[4] = {0, 0, +1, -1},
cdir[4] = {+1, -1, 0, 0};
void CalculatePath(Pos s, int dist)
{
}
int main()
{
FILE *fin = fopen("barbar.in", "r"),
*fout = fopen("barbar.out", "w");
int n, m;
std::queue<Pos> q;
fscanf(fin, "%d %d ", &n, &m);
for(int i = 0; i <= n + 1; i++)
map[i][0] = map[i][m + 1] = WALL;
for(int j = 0; j <= m + 1; j++)
map[0][j] = map[n + 1][j] = WALL;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
fscanf(fin, "%c ", &map[i][j]);
if(map[i][j] == DRAGON)
{
q.push(Pos(i, j));
distmap[i][j] = 1;
}
}
while(!q.empty())
{
Pos p = q.front();
q.pop();
for(int i = 0; i < 4; i++)
{
Pos p2 (p.m_l + ldir[i], p.m_c + cdir[i]);
if(map[p2.m_l][p2.m_c] != WALL && !distmap[p2.m_l][p2.m_c])
{
q.push(p2);
distmap[p2.m_l][p2.m_c] = 1 + distmap[p.m_l][p.m_c];
}
}
}
for(int i = 1; i < n + 1; i++)
{
for(int j = 1; j < m + 1; j++)
printf("%d ", distmap[i][j]);
printf("\n");
}
fcloseall();
return 0;
}