HDU1312 Red and Black(DFS) 2016-07-24 13:49 64人阅读 评论(0) 收藏
Red and Black
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 45 Accepted Submission(s) : 34
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
black tiles.
Write a program to count the number of black tiles which he can reach by repeating the moves described above.
Input
There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.
'.' - a black tile
'#' - a red tile
'@' - a man on a black tile(appears exactly once in a data set)
Output
Sample Input
- 6 9
- ....#.
- .....#
- ......
- ......
- ......
- ......
- ......
- #@...#
- .#..#.
- 11 9
- .#.........
- .#.#######.
- .#.#.....#.
- .#.#.###.#.
- .#.#..@#.#.
- .#.#####.#.
- .#.......#.
- .#########.
- ...........
- 11 6
- ..#..#..#..
- ..#..#..#..
- ..#..#..###
- ..#..#..#@.
- ..#..#..#..
- ..#..#..#..
- 7 7
- ..#.#..
- ..#.#..
- ###.###
- ...@...
- ###.###
- ..#.#..
- ..#.#..
- 0 0
Sample Output
- 45
- 59
- 6
- 13
————————————————————————————————————————————————————
- #include<iostream>
- #include<cmath>
- using namespace std;
- char map[105][105];
- int m, n, t;
- int dir[8][2] = {{ -1, 0 },{ 0, -1 }, { 0, 1 },{1, 0 }};
- void dfs(int si, int sj)
- {
- if (si <= 0 || sj <= 0 || si > m || sj > n)
- return;
- t++;
- for (int i = 0; i < 4; i++)
- {
- if (map[si + dir[i][0]][sj + dir[i][1]] != '#')
- {
- map[si + dir[i][0]][sj + dir[i][1]] = '#';
- dfs(si + dir[i][0], sj + dir[i][1]);
- }
- }
- return;
- }
- int main()
- {
- int si, sj;
- while (cin >> n >> m&&(m||n))
- {
- for (int i = 1; i <= m;i++)
- for (int j = 1; j <= n; j++)
- cin >> map[i][j];
- for (int i = 1; i <= m; i++)
- for (int j = 1; j <= n; j++)
- {
- if (map[i][j] == '@')
- {
- si = i;
- sj = j;
- break;
- }
- }
- map[si][sj] = '#';
- t = 0;
- dfs(si, sj);
- printf("%d\n", t);
- }
- return 0;
- }
HDU1312 Red and Black(DFS) 2016-07-24 13:49 64人阅读 评论(0) 收藏的更多相关文章
- HDU1426 Sudoku Killer(DFS暴力) 2016-07-24 14:56 65人阅读 评论(0) 收藏
Sudoku Killer Problem Description 自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会 ...
- Hdu1010 Tempter of the Bone(DFS+剪枝) 2016-05-06 09:12 432人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU1045 Fire Net(DFS枚举||二分图匹配) 2016-07-24 13:23 99人阅读 评论(0) 收藏
Fire Net Problem Description Suppose that we have a square city with straight streets. A map of a ci ...
- HDU1078 FatMouse and Cheese(DFS+DP) 2016-07-24 14:05 70人阅读 评论(0) 收藏
FatMouse and Cheese Problem Description FatMouse has stored some cheese in a city. The city can be c ...
- HDU2212 DFS 2016-07-24 13:52 56人阅读 评论(0) 收藏
DFS Problem Description A DFS(digital factorial sum) number is found by summing the factorial of eve ...
- HDU1181 变形课(DFS) 2016-07-24 13:31 73人阅读 评论(0) 收藏
变形课 Problem Description 呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒 ...
- leetcode N-Queens/N-Queens II, backtracking, hdu 2553 count N-Queens, dfs 分类: leetcode hdoj 2015-07-09 02:07 102人阅读 评论(0) 收藏
for the backtracking part, thanks to the video of stanford cs106b lecture 10 by Julie Zelenski for t ...
- Red and Black(BFS or DFS) 分类: dfs bfs 2015-07-05 22:52 2人阅读 评论(0) 收藏
Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...
- Hdu1427 速算24点 2017-01-18 17:26 46人阅读 评论(0) 收藏
速算24点 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submiss ...
随机推荐
- 【Java杂记】Equals 和 hashCode
equals 和 hashCode含义 equal:判断两个对象是否相等,如果相同,返回true 否则返回false hashcode: 返回一个int数 Object 默认(内部地址转化为一个数字) ...
- tomcat 设置内存
SET JAVA_OPTS=-Xms256m -Xmx512m -XX:PermSize=256M -XX:MaxPermSize=512M -Xms :初始化堆内存值 -Xmx :堆内存最大值 -X ...
- Fiddler命令行和HTTP断点调试
fiddler设置断点: fiddler->rules->automatic Breakpoints->选择断点方式,这种方式下设定的断点会对之后的所有HTTP请求有效. 有两个断点 ...
- javascritp伪协议
[javascritp伪协议] 将javascript代码添加到客户端的方法是把它放置在伪协议说明符javascript:后的URL中.这个特殊的协议类型声明了URL的主体是任意的javascript ...
- mongo远程登录
1. 进入数据库: use admin db.addUser("foo","foo"); ps:高版本用db.createUser创建. 2. 改配置 如/et ...
- Web站点性能拨测脚本
功能:检测自己本地访问目标网站的返回状态.访问质量信息 [root@localhost src]# cat get_site_status.sh #! /usr/bin/env bash if [[ ...
- 仿微信客户端 帧布局中加入fragment
学习内容来自“慕课网” 这里用Fragment来实现APP主界面 思路: 底部横向排列4个LinearLayout,每个LinearLayout包含一个图片按钮和一个文字 1.默认显示第一个功能(微信 ...
- WebApi是轻量级的,WCF是重量级的,可以Api调用WCF,更灵活
WCF.WebAPI.WCFREST.WebService之间的区别 注明:转载 在.net平台下,有大量的技术让你创建一个HTTP服务,像Web Service,WCF,现在又出了Web API.在 ...
- WCF的例子
Demo的 “Service端”以本机IIS为宿主,“Client端”以WebForm项目为例. 1.新建项目:WCF>WCF Service Application: 2.删除默认文件ISer ...
- vue2.0 MintUI安装和基本使用
http://mint-ui.github.io/docs/#/en2 Mintui 详细地址 基于2.0的安装 npm install mint-ui -S 主要就三行指令 import Mint ...