POJ 1979
这是一道比较水的DPS的题目
题意就是求你可以走到的黑色的地板砖的块数,@代表你的起点,也是黑色的地板砖,#代表白色的,则说明你不能走,这就是一个广搜的题目
思路也很简单,如果你周围的那块地板是黑色的,而且之前没有走过,那就可以往那个地板砖走。
还有这道题的那个初始化很重要,不然很可能会WA。
#include <stdio.h>
#include <iostream>
#include <string.h> using namespace std; int ans;
bool mark[][];
char str_1[][];
void dfs(int m,int n)
{
if(str_1[m+][n]=='.'&&mark[m+][n]){mark[m+][n]=false;ans++;dfs(m+,n);}
if(str_1[m][n+]=='.'&&mark[m][n+]){mark[m][n+]=false;ans++;dfs(m,n+);}
if(str_1[m-][n]=='.'&&mark[m-][n]){mark[m-][n]=false;ans++;dfs(m-,n);}
if(str_1[m][n-]=='.'&&mark[m][n-]){mark[m][n-]=false;ans++;dfs(m,n-);}
} int main()
{
int m,n;
while(scanf("%d%d",&m,&n),m!=&&n!=)
{
for(int i=;i<=n;i++)
scanf("%s",str_1[i]);
memset(mark,true,sizeof(mark));
ans=;
for(int i=;i<=n;i++)
for(int j=;j<m;j++)
if(str_1[i][j]=='@') dfs(i,j);
printf("%d\n",ans);
memset(str_1,,sizeof(str_1));
}
return ;
}
POJ 1979的更多相关文章
- 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 dfs和bfs两种解法
fengyun@fengyun-server:~/learn/acm/poj$ cat 1979.cpp #include<cstdio> #include<iostream&g ...
- OpenJudge/Poj 1979 Red and Black / OpenJudge 2816 红与黑
1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms ...
- poj 1979 Red and Black(dfs)
题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往 ...
- POJ 1979 DFS
题目链接:http://poj.org/problem?id=1979 #include<cstring> #include<iostream> using namespace ...
- POJ 1979 红与黑
题目地址: http://poj.org/problem?id=1979 或者 https://vjudge.net/problem/OpenJ_Bailian-2816 Red and Blac ...
- 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 ...
- POJ 1979 Red and Black
#include<iostream> #include<cstdio> #include<queue> #include<algorithm> #inc ...
随机推荐
- Entity Framework - Using Transactions or SaveChanges(false) and AcceptAllChanges()?
LINK With the Entity Framework most of the time SaveChanges() is sufficient. This creates a transact ...
- 微信C# SDK
微信C# SDK # 模块功能 DLL 1 基础库 Senparc.Weixin.dll 2 微信公众号 / 微信支付 / JSSDK / 摇周边 / 等等 Senparc.Weixin.MP.dll ...
- Html.RenderPartial、Html.RenderAction联系与区别
1.引言 开发人员经常希望应用程序可以在多个不同的地方使用同样的Razor标签和HTML标记代码.这并不需要我们在多个地方重复这些标签,使用MVC中的分部视图和子动作可以让我们很好的解决类似的情况. ...
- PHP与Javascript的混合测试
js调用php <?php $num=88; ?> <script> var a = <?php echo $num;?>; alert(a); </scri ...
- ng-repeat指令使用详解
ng-repeat指令使用详解 link: function(scope,element,attr) scope.$index: if(scope.$last == true){} attr['mng ...
- jsf简介
JSF实现了基于web的以下三个梦想 1.java程序员不必顾虑HTTP的细节,可以按照原本熟悉的事件驱动模型来设计后台系统,并通过一个能担保数据类型无误的数据传递接口将后台系统与前台界面结合在一起. ...
- mysql tinyint
在MySQL的数据类型中,Tinyint的取值范围是:带符号的范围是-128到127.无符号的范围是0到255(见官方<MySQL 5.1参考手册>http://dev.mysql.com ...
- HTML5+ 学习笔记3 storage.增删改查
//插入N条数据 function setItemFun( id ) { //循环插入100调数据 var dataNum = new Number(id); for ( var i=0; i< ...
- C# Winform 脱离 Framework (二)
第一个Method: //启动应用程序 VOID RunApplication(LPTSTR lpFilename, LPTSTR args) { //WinExec(lpFilename, SW_S ...
- .Net程序员必须要知道的东西之HttpModules与HttpHandlers介绍
一.ASP.NET对请求处理的过程: 当客户端请求一个*.aspx文件的时候,这个请求会被inetinfo.exe进程截获,它判断文件的后缀(aspx)之后,将这个请求转交给ASPNET_ISAPI. ...