poj-1979 && hdoj - 1312 Red and Black (简单dfs)
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)的更多相关文章
- POJ 1979 Red and Black (简单dfs)
		
题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...
 - 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 ...
 - HDU 1312:Red and Black(DFS搜索)
		
HDU 1312:Red and Black Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
 - Red and Black(简单dfs)
		
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
 - Hdoj 1312.Red and Black 题解
		
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
 - POJ1979 Red and Black (简单DFS)
		
POJ1979 Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
 - hdu 1312:Red and Black(DFS搜索,入门题)
		
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
 - POJ 1562 && ZOJ 1709 Oil Deposits(简单DFS)
		
题目链接 题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket . 思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接 ...
 - hdoj - 1258 Sum It Up && hdoj - 1016 Prime Ring Problem (简单dfs)
		
http://acm.hdu.edu.cn/showproblem.php?pid=1258 关键点就是一次递归里面一样的数字只能选一次. #include <cstdio> #inclu ...
 
随机推荐
- C# 代码笔记_tuple元组
			
tuple元组: 赋值 List<Tuple<string, int>> cc = new List<Tuple<string, int>>() { n ...
 - 行内元素对齐各种问题--从line-height和vertical-align的角度分析
			
最近研究行内元素的对齐问题,发现img不管怎么设置,下边都有一块留白,强迫症无法忍受未知,于是开始了查阅探索之旅. 辗转来到张鑫旭的博客,他对行内盒子模型做了详细的介绍,包括“幽灵节点”,“line- ...
 - 2019PAT春季考试第4题 7-4 Structure of a Binary Tree (30 分)
			
题外话:考试的时候花了一个小时做了27分,由于Siblings这个单词不知道意思,所以剩下的3分就没去纠结了,后来发现单词是兄弟的意思,气哭~~ 这道题的麻烦之处在于如何从一个字符串中去找数字.先首先 ...
 - 详解java中staitc关键字
			
一.static定义 static是静态修饰符意思,什么叫静态修饰符呢?大家都知道,在程序中任何变量或者代码都是在编译时由系统自动分配内存来存储的,而所谓静态就是指在编译后所分配的内存会一直存在,直到 ...
 - 从0开始搭建SQL Server 2012 AlwaysOn 第二篇(配置故障转移集群)
			
本篇主要讲配置Windows 故障转移集群及遇到的相关问题(坑),因为AlwaysOn是基于Windows的故障转移集群的 在讲解步骤之前需要了解一下故障转移集群仲裁配置 四种集群的仲裁配置: 1.多 ...
 - Vue全局添加组件或者模块
			
import Api from './api.js' export default { install (Vue) { Vue.prototype.$Api = Api } } 这种格式就可以在mai ...
 - nodejs的学习
			
nodejs 就是使用js来编写服务端的程序.它的特性是(单线程 速度快 耗内存多 异步 事件驱动) ( 一些技术的解决方案:默认情况下是 1.不支持多核,可以使用cluster 进行解 ...
 - delphi 7 生成 调用 bat文件的exe文件
			
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
 - java组件不存在解决方案:右侧Maven Projects展开后左上角第一个刷新按钮 刷新后就会从新加载所有java的依赖项了
			
java组件不存在解决方案:右侧Maven Projects展开后左上角第一个刷新按钮 刷新后就会从新加载所有java的依赖项了 软件:idea 问题产生:其他同事进行开发,引入新java组件后提交 ...
 - 如何修改MFC的图标
			
原文:如何修改MFC的图标 修改左上角的图标和任务栏里图标 在对话框构造函数中 CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/) : CDialog(CTestD ...