POJ 1979 Red and Black (简单dfs)
题目:

简单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)的更多相关文章
- poj 1979 Red and Black(dfs水题)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- POJ 1979 Red and Black【DFS】
标准DFS,统计遍历过程中遇到的黑点个数 #include<cstdio> #include<vector> #include<queue> #include< ...
- POJ 1979 Red and Black (DFS)
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- POJ 1979 Red and Black (红与黑)
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS Memory Limit: 30000K Description 题目描述 There is a ...
- poj 1979 Red and Black(dfs)
题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往 ...
- Red and Black(简单dfs)
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- POJ 1979 Red and Black dfs 难度:0
http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...
- 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 ...
- poj 1979 Red and Black 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles ...
随机推荐
- HTTP_PROXY
Linux, macOS, or Unix: $ export HTTP_PROXY=http://a.b.c.d:n $ export HTTPS_PROXY=http://w.x.y.z:m 设置 ...
- 学习篇之SVG
学习篇之SVG 一.use重用 与 g组合 xmlns变量实际上指示浏览器如何解释称为SVG的XML方言 <g></g> 组合 <use /> 重用 <ell ...
- IntelliJ Idea下Go项目开启Debug调试
1.新建Go项目,创建入口go文件(Test1.go),随便写点啥,比如: package main import "fmt" func main(){ fmt.Println(& ...
- .net基础总复习(3)
第三天 2.单例模式 1) 将构造函数私有化 2) 提供一个静态方法,返回一个对象 3) 创建一个单例 3.XML 可扩展的标记语言 XML:存储数据 注意: XML严格区分大小写,并且成对出现 ...
- [置顶]
献给写作者的 Markdown 新手指南
作者:http://jianshu.io/p/q81RER 出处:http://jianshu.io/p/q81RER 献给写作者的 Markdown 新手指南 简书 「简书」作为一款「写作软件」在诞 ...
- laravel contains 的用法
最近在学laravel,做一下学习笔记. 1.contains()方法判断集合是否包含给定的项目: ]);var_dump($collection->contains('Desk'));// t ...
- 相对URL:协议名跨域的一种处理方式
问题现象 当页面地址协议与页面内请求地址协议不一致(不都是https或不都是http)时,往往请求会被拦截.控制台提示: 原因 浏览器对于JavaScript的同源策略的限制,简言之就是我们常说的跨域 ...
- HDU 5914 Triangle
题目来源:2016 CCPC 长春站 题意:青蛙先生想用n个长度为1~n的木棍来组成一些三角形,但是有一个坏蛋就想破坏青蛙先生的好事,请问在这n个木棍中至少偷出来几个木棍使得青蛙先生无法再用剩下的一些 ...
- Java获取当天、本周、本月、本季度、本年等 开始及结束时间
package com.zhaochao.utils; import java.text.SimpleDateFormat; import java.util.Calendar; import jav ...
- WordCount合作--自己部分
前言: (1)合作者:201631062127,201631062625 (2)合作代码地址:WordCount 一.结对的PSP表格: PSP2.1 PSP阶段 预估耗时 (分钟) 实际耗时 (分钟 ...