DFS:Red and Black(POJ 1979)】的更多相关文章

红与黑 题目大意:一个人在一个矩形的房子里,可以走黑色区域,不可以走红色区域,从某一个点出发,他最多能走到多少个房间? 不多说,DFS深搜即可,水题 注意一下不要把行和列搞错就好了,我就是那样弄错过一次哈哈哈哈 #include <stdio.h> #include <stdlib.h> #define MAX_N 20 static int dp[MAX_N][MAX_N]; static int startx; static int starty; static int ans…
Red and Black Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 27891   Accepted: 15142 Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a…
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS    Memory Limit: 30000K Description 题目描述 There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to…
http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; const int maxn = 21; bool vis[maxn][maxn]; char maz[maxn][maxn]; int n,m; const int dx[4] = {1,-1,0,0}; const int dy[4] = {0,0,1,-1}; int ans; bool in(int…
题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往四个方向搜索,会重复搜索,所以使用vis表来标记访问过的点,避免重复搜索. 代码如下: #include <iostream> using namespace std; ; int vis[MAX_N][MAX_N]; char map[MAX_N][MAX_N]; int red_count,…
传送门: poj:http://poj.org/problem?id=1979 zoj:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1165 题目大意: 给你初始坐标,标记为'#'的格子不能走,求你能走的所有格子的个数(能走的为'.',初始坐标用'@'表示) 思路: 一看直接DFS就好了嘛.... 好几天没刷题了,回到家来水一发先~ #include<cstdio> #include<cstring> con…
Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only…
-->Red and Black Descriptions: 有个铺满方形瓷砖的矩形房间,每块瓷砖的颜色非红即黑.某人在一块砖上,他可以移动到相邻的四块砖上.但他只能走黑砖,不能走红砖. 敲个程序统计一下这样可以走到几块红砖上. Input  多组测试用例.每组数组开头有两个正整数W和H:W与H分别表示 x- 与 y- 方向上瓷砖的数量.W和W均不超过20. 还有H行数据,每行包含W个字符.每个字符表示各色瓷砖如下. '.' - 一块黑砖 '#' - 一块红砖 '@' - 一个黑砖上的人(一组数…
标准DFS,统计遍历过程中遇到的黑点个数 #include<cstdio> #include<vector> #include<queue> #include<string> #include<map> #include<iostream> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; const…
Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only…