hdu 1312 Red and Black
Write a program to count the number of black tiles which he can reach by repeating the moves described above.
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)
.#.
.#.
.#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0
#include<iostream>
using namespace std;
char mapp[][];
int m,n,k=,c=,d=;
void dfs(int x,int y)
{
if(mapp[x][y]=='#'||x<||y<||x>=m||y>=n)
{
return;
}
mapp[x][y]='#';
dfs(x+,y);
dfs(x-,y);
dfs(x,y+);
dfs(x,y-);
}
int main()
{
int i,j,k;
while(cin>>n>>m)
{
c=;
d=;
if(m==&&n==)
break;
for(i=;i<m;i++)
{
for(j=;j<n;j++)
{
cin>>mapp[i][j];
}
}
for(i=;i<m;i++)
for(j=;j<n;j++)
{
if(mapp[i][j]=='#')
c++;
}
k=;
for(i=;i<m;i++)
{
for(j=;j<n;j++)
{
if(mapp[i][j]=='@')
{
mapp[i][j]='.';
dfs(i,j);
}
}
}
for(i=;i<m;i++)
for(j=;j<n;j++)
{
if(mapp[i][j]=='#')
d++;
}
cout<<d-c<<endl;
}
return ;
}
hdu 1312 Red and Black的更多相关文章
- HDU 1312 Red and Black --- 入门搜索 BFS解法
HDU 1312 题目大意: 一个地图里面有三种元素,分别为"@",".","#",其中@为人的起始位置,"#"可以想象 ...
- HDU 1312 Red and Black --- 入门搜索 DFS解法
HDU 1312 题目大意: 一个地图里面有三种元素,分别为"@",".","#",其中@为人的起始位置,"#"可以想象 ...
- HDU 1312:Red and Black(DFS搜索)
HDU 1312:Red and Black Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- HDU 1312 Red and Black (dfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 1312 Red and Black(最简单也是最经典的搜索)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 1312 Red and Black(bfs,dfs均可,个人倾向bfs)
题目代号:HDU 1312 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/100 ...
- HDU 1312 Red and Black(DFS,板子题,详解,零基础教你代码实现DFS)
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
- HDU 1312 Red and Black(经典DFS)
嗯... 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 一道很经典的dfs,设置上下左右四个方向,读入时记下起点,然后跑dfs即可...最后答 ...
- HDU 1312 Red and Black (DFS & BFS)
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 题目大意:有一间矩形房屋,地上铺了红.黑两种颜色的方形瓷砖.你站在其中一块黑色的瓷砖上,只能向相 ...
随机推荐
- js获取缓存数据
后台:request.setAttribute("type", type); 前台js获取:var type = "${type}";
- mysql列类型
mysql三大列类型 整型 tinyint(占据空间:1个字节 存储范围 有符号 -128-127 无符号 0-255) smallint mediumint int big ...
- Java集合源码学习(四)HashMap分析
ArrayList.LinkedList和HashMap的源码是一起看的,横向对比吧,感觉对这三种数据结构的理解加深了很多. >>数组.链表和哈希表结构 数据结构中有数组和链表来实现对数据 ...
- asmlinkage
转自:http://www.cnblogs.com/china_blue/archive/2010/01/15/1648523.html 声明,仅为了便于自己记忆和查询,非原创,摘自:http://b ...
- 在asp.net利用jquery.MultiFile实现多文件上传(转载)
转载地址:http://www.cnblogs.com/scy251147/archive/2010/09/30/1839313.html 官网链接:http://www.fyneworks.com/ ...
- [LeetCode] Gas Station
Recording my thought on the go might be fun when I check back later, so this kinda blog has no inten ...
- C++Primer快速浏览笔记-复合类型
C++Primer2.3节介绍了两种复合类型:引用和指针 1.引用 引用并非对象,它只是为一个已经存在的对象所起的别名. 一旦初始化完成,引用将和它的初始值对象一直绑定在一起,不能重新绑定到另一个对象 ...
- Eclipse查看JDK源码
设置 点 "window"-> "Preferences" -> "Java" -> "Installed JR ...
- 遍历List过程中删除元素的正确做法(转)
遍历List过程中删除元素的正确做法 public class ListRemoveTest { 3 public static void main(String[] args) { 4 ...
- 在Salesforce中通过 Debug Log 方式 跟踪逻辑流程
在Salesforce中通过 Debug Log方式 跟踪逻辑流程 具体位置如下所示: Setup ---> Logs ---> Debug Logs ---> Monitored ...