HDu1241 DFS搜索
#include<iostream>
#include<cstring>
using namespace std;
int a[105][105];
int d[8][2]={0,1,0,-1,1,0,-1,0,-1,-1,-1,1,1,-1,1,1}; //八个方向!方向向量。
void dfs(int x,int y)
{
a[x][y]=-1; //相连的无效
for(int i=0;i<8;i++)
{
if(a[x+d[i][0]][y+d[i][1]]==1)
dfs(x+d[i][0],y+d[i][1]); //继续搜索
}
}
int main()
{
int n,m;
while(cin>>n>>m&&(n||m))
{
memset(a,0,sizeof(a)); //拓广边界
int i,j;
char x;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
cin>>x;
if(x=='@')a[i][j]=1;
}
int count=0;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{
if(a[i][j]==1)
{
count++;
dfs(i,j);
}
}
cout<<count<<endl;
}
return 0; }
HDu1241 DFS搜索的更多相关文章
- hdu 1312:Red and Black(DFS搜索,入门题)
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- [ZOJ 1011] NTA (dfs搜索)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1011 题目大意:在一棵树上,给你起始状态,问你能否到达终止状态. ...
- HDU 1312:Red and Black(DFS搜索)
HDU 1312:Red and Black Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
- hihocoder 1050 树中的最长路(动态规划,dfs搜索)
hihocoder 1050 树中的最长路(动态规划,dfs搜索) Description 上回说到,小Ho得到了一棵二叉树玩具,这个玩具是由小球和木棍连接起来的,而在拆拼它的过程中,小Ho发现他不仅 ...
- sdut 2152:Balloons(第一届山东省省赛原题,DFS搜索)
Balloons Time Limit: 1000MS Memory limit: 65536K 题目描述 Both Saya and Kudo like balloons. One day, the ...
- 蓝桥杯 历届试题 剪格子(dfs搜索)
历届试题 剪格子 时间限制:1.0s 内存限制:256.0MB 问题描述 如下图所示,3 x 3 的格子中填写了一些整数. +--*--+--+ |* || +--****--+ ||* | ** ...
- DFS搜索题素数环
素数环: 输入整数1,2,3,4,5,···,n组成一个环,使得相邻两个整数之和均为素数. 输出时从整数1开始逆时针排列.同一个环应恰好输出一次.n<=16. Sample: input: 6 ...
- poj 3083 Children of the Candy Corn 【条件约束dfs搜索 + bfs搜索】【复习搜索题目一定要看这道题目】
题目地址:http://poj.org/problem?id=3083 Sample Input 2 8 8 ######## #......# #.####.# #.####.# #.####.# ...
- codeforces 570 D. Tree Requests 树状数组+dfs搜索序
链接:http://codeforces.com/problemset/problem/570/D D. Tree Requests time limit per test 2 seconds mem ...
随机推荐
- const、let、var的区别
const不能从字面上来理解,他不能修改的是栈内存在的值和地址. 使用const声明的是常量,在后面出现的代码中不能再修改该常量的值. 怎么理解栈内存在的值和地址呢?就要从javascript的类型说 ...
- 朴素贝叶斯分类<转载>
转自http://www.cnblogs.com/leoo2sk/archive/2010/09/17/naive-bayesian-classifier.html 0.写在前面的话 我个人一直很喜欢 ...
- CPP-基础:单目运算符重载
关于++运算符前置和后置重载的实现实例: #include <iostream> using namespace std; //创建时钟类 class Clock { public: Cl ...
- kubernetes添加不了google apt-key
转自icepoint的博客 key来源 我的百度云盘 密码:v3wo 下载kube_apt_key.gpg到本地,上传到服务器后执行下面的命令 apt-get update && ap ...
- Log4J的配置与使用详解
一.简介 Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口服务器.NT的事件记录器.UNIX Syslog守护 ...
- nginx在windows上面的启动bat文件
因为windows上面zip安装nginx后启动比较麻烦,然后找了一下关于批处理文件的资料,写了一个nginx启动和关闭的脚本. 这个脚本正常情况下是可以使用的.因为脚本中并没有对nginx程序是否在 ...
- MySQL binlog-server搭建
MySQL binlog-server搭建 binlog在备份中起着至关重要的作用,备份binlog文件时,只能先在本地备份,然后才能传送到远程服务器上.从MySQL5.6版本后,可以利用mysqlb ...
- scrollTop如何实现click后页面过渡滚动到顶部
用JS操作,body元素的scrollTop var getTop = document.getElementById("get-top"); var head = documen ...
- perl学习之:正则表达式
- cvs 文件无法上传debug
当时文件始终上传不成功时(一般先update后commit): cvs update filename report:move away filename ,it is in the way cvs ...