记录编号 |
175695 |
评测结果 |
AAAAAAAAAAAAAAAA |
题目名称 |
[POI 1999] 位图 |
最终得分 |
100 |
用户昵称 |
啊吧啦吧啦吧 |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.106 s |
提交时间 |
2015-08-06 19:59:32 |
内存使用 |
0.44 MiB |
显示代码纯文本
#include <iostream>
#include <algorithm>
#include <queue>
#include <fstream>
using namespace std;
ifstream fin("bit.in");
ofstream fout("bit.out");
#define cin fin
#define cout fout
const int MAX(183), dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int n, m, ans[MAX][MAX];
bool pd[MAX][MAX] = {false};
queue<pair<int, int> > q;
main()
{
char y;
// ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j){
cin >> y;
if (y == '1'){
ans[i][j] = 0;
pd[i][j] = true;
q.push(make_pair(i, j));
}
}
while(! q.empty()){
int lx = q.front().first, ly = q.front().second;
q.pop();
for (int i = 0; i < 4; ++i){
int nx = lx + dx[i], ny = ly + dy[i];
if (nx > 0 && nx <= n && ny > 0 && ny <= m && (! pd[nx][ny])){
pd[nx][ny] = true;
ans[nx][ny] = ans[lx][ly] + 1;
q.push(make_pair(nx, ny));
}
}
}
for (int i = 1; i <= n; ++i){
for (int j = 1; j <= m; ++j){
if (j > 1)
cout << ' ';
cout << ans[i][j];
if (j == m && i != n)
cout << endl;
}
}
// for(;;);
}