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 ...
随机推荐
- HDU 1716 排列2
排列2 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- ZJOI2005沼泽鳄鱼
矩阵优化dp ** 注意:矩阵乘法没有交换律 ** 思路:类比P2151hh去散步 代码特点在一维的答案矩阵 1.矩阵优化两点间方案数不必赘述 2.注意2,3,4可以办到以他们的lcm为周期,正是因为 ...
- 用Ngen指令加快C#程序的启动速度
用Ngen指令加快C#程序的启动速度 由于C#是使用实时 (JIT) 编译器编译原始程序集.因此第一次运行C#程序(或Dll)时,程序的启动非常慢.为了提高用户的体验,可以用Microsoft的供的本 ...
- poj3244(公式题)
Difference between Triplets Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2476 Acce ...
- poj 2480 Longge's problem 积性函数性质+欧拉函数
题意: 求f(n)=∑gcd(i, N) 1<=i <=N. 分析: f(n)是积性的数论上有证明(f(n)=sigma{1<=i<=N} gcd(i,N) = sigma{d ...
- Multiple CPUs,Multiple Cores、Hyper-Threading
CPU Basics: Multiple CPUs, Cores, and Hyper-Threading Explained 现在多数的家用电脑,仍然使用的是 Single CPU,Multiple ...
- HDU 2988 Dark roads(kruskal模板题)
Dark roads Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- vue踩坑记-在项目中安装依赖模块npm install报错
在维护别人的项目的时候,在项目文件夹中安装npm install模块的时候,报错如下: npm ERR! path D:\ShopApp\node_modules\fsevents\node_modu ...
- 在 Swift 專案中使用 Javascript:編寫一個將 Markdown 轉為 HTML 的編輯器
原文:Using JavaScript in Swift Projects: Building a Markdown to HTML Editor 作者:GABRIEL THEODOROPOULOS ...
- leetCode解题报告5道题(十)
题目一:Valid Number Validate if a given string is numeric. Some examples: "0" => true &quo ...