题目:

简单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. POJ 1128 Frame Stacking 拓扑排序+暴搜

    这道题输出特别坑.... 题目的意思也不太好理解.. 就解释一下输出吧.. 它让你 从下往上输出. 如果有多种情况,按照字典序从小往大输出... 就是这个多种情况是怎么产生的呢. 下面给一组样例. 很 ...

  2. 从DataTable高效率导出数据到Excel

    首先从数据库读取数据到DataTable,这我就不提了,大家都明白.下面直接介绍如何从DataTable高效率导出数据到Excel中的方法,代码如下: using Microsoft.Office.I ...

  3. ZBrush软件特性之Marker标记调控板

    在ZBrush®中使用Marker标记调控板来记忆物体属性,因此能在任何时间回到标记并使用它给其他物体或改变物体作为参考点. ZBrush软件下载:http://pan.baidu.com/s/1sl ...

  4. 构造器参数过多时考虑使用构建器(Builder)

    一.静态工厂和构造器的局限性 面对需要大量可选参数才能构建对象时,静态工厂和构造器并不能随着可选参数的增加而合理扩展. 假设创建一个类Person需要使用大量的可选参数,其中两个参数是必填的,剩下的都 ...

  5. Parameter ‘brOrderNo’ not found

    org.apache.ibatis.binding.BindingException: Parameter 'brOrderNo' not found. Available parameters ar ...

  6. K3内部表数据名称

    在后台数据库ICClassType表中,字段FID<0的是老单,FID>0的是新单.----------------系统设置------------------------FStatus: ...

  7. virtualenv和virtualenvwrapper的安装与使用

    环境 Windows 10 python 3.6.7 virtualenv 安装 virtualenv用于创建虚拟环境,用于隔离不同的python版本的运行,是容器类软件.这里在Windows下通过p ...

  8. Jetty初探

    一.在jetty中部署web应用 Jetty 和 Tomcat 一样都是一个web server的container, 用户可以在里面 deploy 自己的 war 包,然后启动 Jetty, 进而通 ...

  9. BZOJ 2402 陶陶的难题II (01分数规划+树剖+线段树+凸包+二分)

    题目大意:略 一定范围内求最大值,考虑二分答案 设现在选择的答案是$mid$,$max \left \{ \frac{yi+qj}{xi+pj} \right \} \geq mid $ 展开可得,$ ...

  10. 【codeforces 757E】Bash Plays with Functions

    [题目链接]:http://codeforces.com/problemset/problem/757/E [题意] 给你q个询问; 每个询问包含r和n; 让你输出f[r][n]; 这里f[0][n] ...