http://poj.org/problem?id=1979

基础搜索。

 #include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout);
#define maxn 1000000000
#define N 25
using namespace std; char filed[][];
int w,h,sum;
int dir[][]={-,,,,,,,-}; void dfs(int x,int y)
{
for(int i=;i<;i++)
{
int xx=x+dir[i][];
int yy=y+dir[i][];
if(xx>=&&xx<h&&yy>=&&yy<w&&filed[xx][yy]=='.')
{
sum++;
filed[xx][yy]='#';
dfs(xx,yy);
}
}
}
int main()
{
//freopen("a.txt","r",stdin);
while(~scanf("%d%d",&w,&h)&&w+h)
{
getchar();
for(int i=;i<h;i++)
scanf("%s",filed[i]);
int a,b;
for(int i=;i<h;i++)
for(int j=;j<w;j++)
if(filed[i][j]=='@')
{
a=i;
b=j;
}
//printf("%d %d\n",a,b);
sum=;
filed[a][b]='#';
dfs(a,b);
printf("%d\n",sum);
}
return ;
}

poj-1979 && hdoj - 1312 Red and Black (简单dfs)的更多相关文章

  1. POJ 1979 Red and Black (简单dfs)

    题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...

  2. HDU 1312 Red and Black (dfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...

  3. HDU 1312:Red and Black(DFS搜索)

      HDU 1312:Red and Black Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  4. Red and Black(简单dfs)

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. Hdoj 1312.Red and Black 题解

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

  6. POJ1979 Red and Black (简单DFS)

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

  7. hdu 1312:Red and Black(DFS搜索,入门题)

    Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  8. POJ 1562 && ZOJ 1709 Oil Deposits(简单DFS)

    题目链接 题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket . 思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接 ...

  9. hdoj - 1258 Sum It Up && hdoj - 1016 Prime Ring Problem (简单dfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1258 关键点就是一次递归里面一样的数字只能选一次. #include <cstdio> #inclu ...

随机推荐

  1. android开发学习 ------- volley网络请求的实例

    在  http://www.sojson.com/httpRequest/  上对http进行访问,将此访问在android中的应用 ********************************* ...

  2. 技术杂记之:vi使用入门

    对于Linux的初次使用者来说,进入Linux非图形界面后,不知道怎么创建文本(甚至于在图形界面,也找不到创建文本的菜单).其实,每一个Linux的发行版本,都包含了一个最简单.也是最基础的文本编辑器 ...

  3. rar在linux下安装更新

    1.下载:根据主机系统下载合适的版本,当前64为centos系统演示下载: wget http://www.rarlab.com/rar/rarlinux-x64-5.3.0.tar.gz 2.解压安 ...

  4. php高效率对一维数组进行去重

    $input = array("a" => "green", "red", "b" => "gre ...

  5. Protostuff序列化和反序列化

    序列化和反序列化是在应对网络编程最常遇到的问题之一. 序列化就是将Java Object转成byte[]:反序列化就是将byte[]转成Java Object. 这里不介绍JDK serializab ...

  6. mac webstrom 安装less

    1.检验电脑是否安装less lessc -v 2.如果没有执行全局安装命令 npm install -g less 3.webstrom -> Preferencs-> File Wat ...

  7. bzip2 一种块排序文件压缩软件

    总览 bzip2 [ -cdfkqstvzVL123456789 ] [ filenames ... ] bunzip2 [ -fkvsVL ] [ filenames ... ] bzcat [ - ...

  8. 面包屑 asp代码记录 newsmulu_class 内部函数

    'id 这里其实是 classId 'mbStr1 最右边的栏目模板 由于是当前本页面 就不带链接了 建议默认值:<span class='mbxC'>$title</span> ...

  9. pycharm 编写前端代码一些小技巧

    <!DOCTYPE html><html lang="zh-CN"><head> <meta charset="UTF-8&qu ...

  10. mac 下安装python pil

    mac:sudo brew install freetype sudo pip install pillow ubuntu: sudo apt-get install libfreetype6-dev ...