简单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. Jenkins的错误“error fetching remote repo origin”的问题解决

    错误如上,解决方法收集,可以尝试以下方法: http://stackoverflow.com/questions/38391601/jenkins-error-error-fetching-remot ...

  2. JAVA ,SSH中文及其乱码问题的解决 6大配置点 使用UTF-8编码

    JSP,mysql,tomcat下(基于struts2)中文及其乱码问题的解决 6大配置点 使用UTF-8编码 目前对遇到J2EE 开发中 中文及其乱码问题,参考网上资料做个总结, 主要是6大配置点: ...

  3. LAMP php5.4编译 _php_image_stream_putc等问题

    编译时出现下列问题时: In file included from /usr/local/src/php-5.4.6/ext/gd/gd.c:103: /usr/local/src/php-5.4.6 ...

  4. apache 配置https(转)

    主要讲述在windows下apache配置SSL以实现http转换为https SSL: SSl是为Http传输提供安全的协议,通过证书认证来确保客户端和网站服务器之间的数据是安全.也就是说在SSL下 ...

  5. Two-Phase-Commit for Distributed In-Memory Caches--reference

    Part I reference from:http://gridgain.blogspot.kr/2014/09/two-phase-commit-for-distributed-in.html 2 ...

  6. Android Studio导入GitHub上的项目常见问题(以图片轮播开源项目为实例)

    前言:github对开发者而言无疑是个宝藏,但想利用它可不是件简单的事,用Android studio导入开源项目会遇到各种问题,今天我就以github上的一个图片轮播项目为例,解决导入过程中的常见问 ...

  7. 2015 UESTC Winter Training #8【The 2011 Rocky Mountain Regional Contest】

    2015 UESTC Winter Training #8 The 2011 Rocky Mountain Regional Contest Regionals 2011 >> North ...

  8. N皇后问题--递归回溯

    著名的N皇后问题,就是先按照行一行一行的找,先找第一行,第一行找到一列能满足条件,继续找下一行,如果下一行也找到一列能满足条件,继续找下一行,一次类推,最终找到解, 但是,如果找不到的话, 就说明上一 ...

  9. Gamit解算脚本

    这是一个解算单天的shell脚本,对于初学者很有帮助. 首先就是需要在项目(四个字符)建立rinex brdc igs 还有以年纪日命名的目录,然后提前准备好station.info和lfile.文件 ...

  10. HDU3756

    题意:给定三围空间里面某些点,求构造出一个棱锥,将所有点包含,并且棱锥的体积最小. 输入: T(测试数据组数) n(给定点的个数) a,b,c(对应xyz坐标值) . . . 输出: H(构造棱锥的高 ...