POJ 1979 Red and Black (zoj 2165) DFS
传送门:
poj:http://poj.org/problem?id=1979
zoj:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1165
题目大意:
给你初始坐标,标记为'#'的格子不能走,求你能走的所有格子的个数(能走的为‘.’,初始坐标用‘@’表示)
思路:
一看直接DFS就好了嘛。。。。
好几天没刷题了,回到家来水一发先~
#include<cstdio>
#include<cstring>
const int MAXN=21+2;
char map[MAXN][MAXN];
bool vis[MAXN][MAXN];
int ans;
int m,n;
void dfs(int x,int y)
{
if(vis[x][y]==true||map[x][y]=='#')
return; vis[x][y]=true;
ans++; if(x!=0)
dfs(x-1,y);
if(y!=0)
dfs(x,y-1);
if(x!=n-1)
dfs(x+1,y);
if(y!=m-1)
dfs(x,y+1); }
int main()
{ while(~scanf("%d%d",&m,&n),n||m)
{
memset(vis,0,sizeof(vis));
ans=0;
for(int i=0;i<n;i++)
scanf("%s",map[i]);
int begin_x,begin_y; for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if(map[i][j]=='@')
{
begin_x=i;
begin_y=j;
} dfs(begin_x,begin_y);
printf("%d\n",ans);
}
return 0;
}
POJ 1979 Red and Black (zoj 2165) DFS的更多相关文章
- 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 难度:0
http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; ...
- poj 1979 Red and Black(dfs)
题目链接:http://poj.org/problem?id=1979 思路分析:使用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 (简单dfs)
题目: 简单dfs,没什么好说的 代码: #include <iostream> using namespace std; typedef long long ll; #define IN ...
- poj 1979 Red and Black 题解《挑战程序设计竞赛》
地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles ...
- OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑
1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...
随机推荐
- 亲测有效的解决在vue cli@3 create 命令执行后 node-sass无法安装上的问题
在使用Vue cli@3 搭建工程手脚架的过程中.当我们选择了采用 sass 处理 css 编译.在使用vue create test 命令行执行到最后.会到以下这步:然后开始报错: Download ...
- Es5正则
##JSON(ES5) 前端后台都能识别的数据.(一种数据储存格式) XNL在JSON出来前 JSON不支持 undefinde和函数. 示列:let = '[{"useername&qu ...
- react-native React Native version mismatch
android/app/build.gradle file: dependencies { compile fileTree(dir: "libs", include: [ ...
- 微信小程序从零开始开发步骤(四)自定义分享的功能
上一章节,实现了小程序的底部导航的功能,这一节开始实现一些简单的功能.本章节介绍的是小程序的自定义分享的功能. 可以分享小程序的任何一个页面给好友或群聊.注意是分享给好友或群聊,并没有分享到朋友圈.一 ...
- Java数据传递实验
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 在开发过程中,我们经常会遇到对象传递的问题,有时仅仅传递数据,有时却要实现数据同步:这时,就要分清两 ...
- 洛谷 P1105 平台
P1105 平台 题目描述 空间中有一些平台.给出每个平台的位置,请你计算从每一个平台的边缘落下之后会落到哪一个平台上.注意,如果某两个平台的某个两边缘横坐标相同,物体从上面那个平台落下之后将不会落在 ...
- 【Cocos2d-x 017】 多分辨率适配全然解析
转:http://blog.csdn.net/w18767104183/article/details/22668739 文件夹从Cocos2d-x 2.0.4開始,Cocos2d-x提出了自己的多分 ...
- 玲珑杯 Round 19 A simple math problem
Time Limit:2s Memory Limit:128MByte Submissions:1599Solved:270 DESCRIPTION You have a sequence anan, ...
- Git提交.net项目的小问题
今天早上写了点关于asp.net core授权的东西,输入git add .的时候出现的报错 $ git add .error: open(".vs/DOTNETAuthorization/ ...
- 关于java中String的一点理解
String类是java的最基本类之中的一个,非常好的掌握它的原理非常是必要的! 1.String的Final类型的.是不可继承 的.final类默认的方法都为final类型,保证了方法不能被 ...