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 ...
随机推荐
- 设置电脑IP
1.首先在Win7桌面上找到“网络”入口,如下图: 进入Win7网络 2.进入网络之后我们再点击顶部的“网络共享中心”,如下图: 进入Win7网络共享中心 3.进入Win7网络共享中心之后,我 ...
- ASP.NET MVC数据库初始化
public class DBInitializer:DropCreateDatabaseAlways<BookDBContext> { protected override void S ...
- AJPFX分析int 和integer的区别
int是java提供的8种原始数据类型之一.Java为每个原始类型提供了封装类,Integer是java为int提供的封装类.int的默认值为0,而Integer的默认值为null,即Integer可 ...
- mvc的生命周期
尽管每次都是从msdn里复制粘贴,但是还是有必要的,加深对mvc的理解和官方的表述. 了解 MVC 应用程序执行过程 发送给基于 ASP.NET MVC 的 Web 应用程序的请求首先通过 UrlRo ...
- 2017广东工业大学程序设计竞赛决赛 H tmk买礼物
题意: Description 今天是校赛的日子,为了庆祝这么喜庆的日子,TMK打算买些礼物给女票LSH庆祝一下. TMK进入了雪梨超市,然后刚踏入的一瞬间,店主就对TMK说:“恭喜你成为了本店第21 ...
- 关于Android软键盘把布局顶上去的问题(一)
最近接触到了一个登陆页面,布局最上面显示的是一个波纹的view,中间显示账号和密码的EditText,紧接着还有一个Button: 希望:点击EditText时,软键盘不能把波纹的view顶出去,也不 ...
- Java线程-线程的基本状态
问题:线程有哪些基本状态?这些状态是如何定义的? 新建(new):新创建了一个线程对象. 可运行(runnable):线程对象创建后,其他线程(比如main线程)调用了该对象的start()方法.该状 ...
- 获取当前时间(日期格式) && 获取当前加一年的时间(日期格式)
获取当前时间,日期格式function currentDate() { var date = new Date(); var y = date.getFullYear(); var m = date. ...
- tensorflow ConfigProto
tf.ConfigProto一般用在创建session的时候.用来对session进行参数配置 with tf.Session(config = tf.ConfigProto(...),...)#tf ...
- Windows下如何使用CMD命令进入MySQL数据库
1.打开[开始]>[运行]输入[cmd]单击[确定]后出现CMD命令黑色窗口,这就是我们说的CMD命令行,或者使用快捷键Windows键(在键盘上有个Windows标志的按键)+R输入cmd后回 ...