简单BFS。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
using namespace std; #define MAXN 105 typedef struct node_t {
int x, y;
node_t() {}
node_t(int xx, int yy) {
x = xx; y = yy;
}
} node_t; char map[MAXN][MAXN];
char ans[MAXN][MAXN];
bool visit[MAXN][MAXN];
int dir[][] = {
{-,},{,},{,},{,-},
{,},{,-},{-,},{-,-}
};
node_t s;
int n; bool check(int x, int y) {
return x< || x>=n || y< || y>=n;
} void bfs() {
int i, j, k, tmp;
int x, y, v;
int xx[], yy[], m;
queue<node_t> Q;
node_t nd; memset(visit, false, sizeof(visit));
memset(ans, '.', sizeof(ans));
visit[s.x][s.y] = true;
for (i=; i<n; ++i)
ans[i][n] = '\0';
Q.push(s); while (!Q.empty()) {
nd = Q.front();
Q.pop();
v = m = ;
for (i=; i<; ++i) {
x = nd.x + dir[i][];
y = nd.y + dir[i][];
if (check(x, y))
continue;
xx[m] = x;
yy[m] = y;
++m;
if (map[x][y] == 'X')
++v;
}
ans[nd.x][nd.y] = v+'';
if (v == ) {
for (i=; i<m; ++i) {
if (!visit[xx[i]][yy[i]]) {
visit[xx[i]][yy[i]] = true;
Q.push(node_t(xx[i], yy[i]));
}
}
}
}
} int main() {
int i, j; #ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif while (scanf("%d", &n) != EOF) {
for (i=; i<n; ++i)
scanf("%s", map[i]);
scanf("%d %d", &s.x, &s.y); if (map[s.x][s.y] == 'X') {
printf("it is a beiju!\n\n");
} else {
bfs();
for (i=; i<n; ++i)
printf("%s\n", ans[i]);
printf("\n");
}
} return ;
}

【HDOJ】3316 Mine sweeping的更多相关文章

  1. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

  2. 【HDOJ】4341 Gold miner

    分组01背包.在一条直线上的点归为一组. /* 4341 */ #include <iostream> #include <sstream> #include <stri ...

  3. 【HDOJ】【3506】Monkey Party

    DP/四边形不等式 裸题环形石子合并…… 拆环为链即可 //HDOJ 3506 #include<cmath> #include<vector> #include<cst ...

  4. 【HDOJ】【3516】Tree Construction

    DP/四边形不等式 这题跟石子合并有点像…… dp[i][j]为将第 i 个点开始的 j 个点合并的最小代价. 易知有 dp[i][j]=min{dp[i][j] , dp[i][k-i+1]+dp[ ...

  5. 【HDOJ】【3480】Division

    DP/四边形不等式 要求将一个可重集S分成M个子集,求子集的极差的平方和最小是多少…… 首先我们先将这N个数排序,容易想到每个自己都对应着这个有序数组中的一段……而不会是互相穿插着= =因为交换一下明 ...

  6. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  7. 【HDOJ】【3415】Max Sum of Max-K-sub-sequence

    DP/单调队列优化 呃……环形链求最大k子段和. 首先拆环为链求前缀和…… 然后单调队列吧<_<,裸题没啥好说的…… WA:为毛手写队列就会挂,必须用STL的deque?(写挂自己弱……s ...

  8. 【HDOJ】【3530】Subsequence

    DP/单调队列优化 题解:http://www.cnblogs.com/yymore/archive/2011/06/22/2087553.html 引用: 首先我们要明确几件事情 1.假设我们现在知 ...

  9. 【HDOJ】【3068】最长回文

    Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...

随机推荐

  1. (五)unity4.6Ugui中文教程文档-------概要-UGUI Interaction Components

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMDAxOTcxNw==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  2. HDU1247 Hat’s Words 【trie树】

    Hat's Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  3. boost 特点

    功能强大 跨平台 开源 免费 构造精巧 C++扩展库

  4. LSI MegaCl i命令使用1

    MegaCli命令使用:cd /opt/MegaRAID/MegaCli/MegaCli -AdpAllInfo -aAll     [显示所有适配器信息]MegaCli -LDInfo -Lall ...

  5. NYOJ -37回文字符串

    这道题看了好大会没有思路,上网一搜发现这么简单,但是我为什么就想不到呢,??就是求和它的逆序之后的字符串最长公共子序列,然后用总的长度减去它就行了.原因是是因为只要是在公共子序列里面,那么他就是对称的 ...

  6. 【转】node-webkit:开发桌面+WEB混合型应用的神器

    顾名思义,node-webkit就是nodejs+webkit. 这样做的好处显而易见,核心奥义在于,用nodejs来进行本地化调用,用webkit来解析和执行HTML+JS. 快速上手 下载node ...

  7. Javascipt 时间格式化(日期)

    Date.prototype.format =function(format){ var o = { "M+" : this.getMonth()+1, //month " ...

  8. WCF调用问题

    1---WCF常用的节点绑定 basicHttpBinding和netTcpBinding 当通过Spring对象注入 如 WCFForOrderService 对象注入 public WCFForO ...

  9. osgi与webservice

    osgi简介: http://osgia.com/ http://blog.csdn.net/xiaokui008/article/details/9662933 http://wdhdd889.it ...

  10. Cacti监控Windows主机,Windows主机的正确配置

    使用cacti监控Windows主机的时候经常遇到无法获取Windows主机的snmp信息和Windows主机的硬件信息,主要原因是Windows主机没有正确配置snmp,以下是正确的配置步骤:1.安 ...