**链接 : ** Here!

**思路 : ** 简单的搜索, 直接广搜就ok了.


/*************************************************************************
> File Name: E.cpp
> Author:
> Mail:
> Created Time: 2017年11月26日 星期日 10时51分05秒
************************************************************************/ #include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
using namespace std; #define MAX_N 30
int N, M, total_num;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
int vis[MAX_N][MAX_N];
char G[MAX_N][MAX_N]; struct Point {
Point() {}
Point(int x, int y) : x(x), y(y) {}
int x, y;
};
Point st; bool check(Point pt) {
if (pt.x < 0 || pt.x >= N || pt.y < 0 || pt.y >= M) return false;
if (vis[pt.x][pt.y]) return false;
if (G[pt.x][pt.y] == '#') return false;
return true;
}
void DFS(Point pt) {
++total_num;
vis[pt.x][pt.y] = 1;
for (int i = 0 ; i < 4 ; ++i) {
Point temp(pt.x + dx[i], pt.y + dy[i]);
if(!check(temp)) continue;
vis[temp.x][temp.y] = 1;
DFS(temp);
}
} void solve() {
memset(vis, 0, sizeof(vis));
for (int i = 0 ; i < N ; ++i) {
for (int j = 0 ; j < M ; ++j) {
if (G[i][j] == '@') {
st.x = i; st.y = j;
break;
}
}
}
DFS(st);
printf("%d\n", total_num);
}
void read() {
for (int i = 0 ; i < N ; ++i) {
getchar();
scanf("%s", G[i]);
}
}
int main() {
// freopen("./in.in", "r", stdin);
while (scanf("%d%d", &M, &N) != EOF) {
if (N == 0 && M == 0) break;
memset(G, 0, sizeof(G));
total_num = 0;
read();
solve();
}
return 0;
}

POJ 1979 Red and Black (BFS)的更多相关文章

  1. POJ 1979 Red and Black (红与黑)

    POJ 1979 Red and Black (红与黑) Time Limit: 1000MS    Memory Limit: 30000K Description 题目描述 There is a ...

  2. OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑

    1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...

  3. poj 1979 Red and Black 题解《挑战程序设计竞赛》

    地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles ...

  4. POJ 1979 Red and Black dfs 难度:0

    http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...

  5. poj 1979 Red and Black(dfs)

    题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往 ...

  6. POJ 1979 Red and Black (zoj 2165) DFS

    传送门: poj:http://poj.org/problem?id=1979 zoj:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problem ...

  7. POJ 1979 Red and Black

    #include<iostream> #include<cstdio> #include<queue> #include<algorithm> #inc ...

  8. HDOJ 1312 (POJ 1979) Red and Black

    Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...

  9. poj 1979 Red and Black(dfs水题)

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

随机推荐

  1. [E2E] Visual Differing Tests with Puppeteer and PixelMatch

    Take your end to end tests to the next level by comparing your current application's view with an al ...

  2. rac_grid自检无法正常进行报PRVF-4007

    原创作品,出自 "深蓝的blog" 博客.欢迎转载,转载时请务必注明下面出处.否则追究版权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlo ...

  3. 检测含有挖矿脚本的WiFi热点——果然是天下没有免费的午餐

    见:http://www.freebuf.com/articles/web/161010.html 本质上是在开放wifi热点,自己搭建挖掘的网页,让接入的人访问该网页. 802.11无线协议本身特点 ...

  4. B2002 [Hnoi2010]Bounce 弹飞绵羊 分块

    原来做过,看大家都做这道题都热情高涨,沈爷爷debug这道题4天,作为告诉他这个题的人,我还有点不好意思...我自己也就做了一个小时. 其实这个题思路还好,就是维护每个点的出块次数和跳出块的位置,然后 ...

  5. 完美解决 linux sublime 中文无法输入

    感谢oschina 中几位前辈的分享 下面是我结合自己的情况所配置的具体步骤: 系统环境: ubuntu 12.10 输入法:fcitx fcitx 安装 apt-get install fcitx ...

  6. [Swift]实现优先队列PriorityQueue

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. this引用逃逸问题

    //this引用逃逸 // 1.构造器还未完成前,将自身this引用向外抛,使其他线程访问这个引用,进而访问到其未初始化的变量,造成问题 // 2.内部类访问外部类未初始化的成员变量 //3.多态继承 ...

  8. MSSQL:账号无法删除方案

    1.查询 EXEC sp_who 'WIN-GBKBCVTG4CN\Administrator' 返回一个表格,其中有列[spid] 2.删除 kill spid

  9. strcpy自实现

    为了避免strcpy源串覆盖问题(P220),自实现strcpy. #include <stdio.h> #include <string.h> #include <as ...

  10. SQLServer2008 关于while循环

    有这样一个表tbl id  code name 11   a      aa/bb/cc 22   b      ee/rr/tt 需要将name段根据‘/’拆分开来,变成新的数据行 即: id  c ...