题目:

简单dfs,没什么好说的

代码:

#include <iostream>
using namespace std;
typedef long long ll;
#define INF 2147483647 int w,h;
char a[][];
int dir[][] = {-,,,,,-,,};
int ans = ; void dfs(int x,int y){
if(x < || x >= h || y < || y >= w || a[x][y] == '#') return;
ans++;
a[x][y] = '#';
for(int i = ;i < ; i++){
dfs(x+dir[i][],y+dir[i][]);
}
} int main(){
while(cin >> w >> h){
if(w == && h == ) break;
ans = ;
int sx,sy;
for(int i = ;i < h; i++){
for(int j = ;j < w; j++){
cin >> a[i][j];
if(a[i][j] == '@'){
sx = i;sy = j;
}
}
}
dfs(sx,sy);
cout << ans << endl;
}
return ;
}

POJ 1979 Red and Black (简单dfs)的更多相关文章

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

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

  2. POJ 1979 Red and Black【DFS】

    标准DFS,统计遍历过程中遇到的黑点个数 #include<cstdio> #include<vector> #include<queue> #include< ...

  3. POJ 1979 Red and Black (DFS)

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

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

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

  5. poj 1979 Red and Black(dfs)

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

  6. Red and Black(简单dfs)

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

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

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

  8. 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 ...

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

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

随机推荐

  1. Redis学习笔记(二) Redis 数据类型

    Redis 支持五种数据类型:string(字符串).list(列表).hash(哈希).set(集合)和 zset(有序集合),接下来我们讲解分别讲解一下这五种类型的的使用. String(字符串) ...

  2. c#常量如何使用

    c#中类中定义一个常量,在其他地方使用的时候使用类名.常量

  3. View的呈现(二)加载流程

    这块涉及到Code+Razor模板=>html[output流] 而这块的问题在于Razor最后生成了什么?--对象:一个类文件:eg:index.cshtml  => index_cst ...

  4. 脚本_统计固定时间段服务器的访问量.sh

    #!bin/bash#功能:统计 1:30 到 4:30 所有访问 apache 服务器的请求有多少个#作者:liusingbon#awk 使用-F 选项指定文件内容的分隔符是/或者:#条件判断$7: ...

  5. java的插入排序

    import java.util.Scanner;public class test22 { public static void main(String[] args) {  Scanner in= ...

  6. Python笔记26----正则表达式匹配

    1.语法: 2.题目1:数据类型: 如果要选择 time 为2014-12-18那天的数据:采用正则化来处理 代码:   import re regex = re.compile(r'^2014-12 ...

  7. 广义线性模型------逻辑回归和softmax回归

    1.广义线性模型 2.逻辑回归 3.softmax回归

  8. 移动设备safari不支持jquery的live绑定的解决方案

    给元素加上样式如下即可 <style> .btn{ cursor: pointer; } </style>

  9. 关于samsung连接BLE设备的一些资料汇总和开发过程一些经验总结

    1 忙了这么久,终于有时间把最近几个月弄的东西整理一下,顺便我的开发过程和经历. 被公司分到做一个蓝牙4.0的项目,对这种软硬结合的东西也比较感兴趣,所以很快投入到android蓝牙4.0的项目中来. ...

  10. thinkPHP的Excel插件

    原文地址 http://www.thinkphp.cn/topic/14005.html 总结的注意事项 1实例化第三方类,要在类名前加\ ,不然引用地址不对. 实现步骤:一:在http://phpe ...