hud 1241 dfs连同块
#include <stdio.h> #include <iostream> #include <string> #include <string.h> #include <cmath> #include <math.h> #include <algorithm> #include <set> #include <map> using namespace std; #define Maxn 1000 int hang,lie; char MAP[Maxn][Maxn]; int dir[8][2] = { {1,0}, {-1,0}, {0,1}, {0,-1}, {1,1}, {1,-1}, {-1,1}, {-1,-1} }; void dfs(int x,int y) { MAP[x][y] = '*'; for(int i = 0; i < 8; i++) { int xx = x + dir[i][0]; int yy = y + dir[i][1]; if (xx >= 0 && xx < hang && yy >= 0 && yy < lie && MAP[xx][yy] != '*') { dfs(xx,yy); } } } int main() { while(cin >> hang >> lie,hang+lie) { int k = 0; for (int i = 0; i < hang; i++) { scanf("%s",MAP[i]); } for(int i = 0; i < hang; i++) { for(int j = 0; j < lie; j++) { if (MAP[i][j] == '@') { dfs(i,j); k++; } } } printf("%d\n",k); } }
hud 1241 dfs连同块的更多相关文章
- DFS(连通块) HDU 1241 Oil Deposits
题目传送门 /* DFS:油田问题,一道经典的DFS求连通块.当初的难题,现在看上去不过如此啊 */ /************************************************ ...
- HDU 1241 (DFS搜索+染色)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1241 题目大意:求一张地图里的连通块.注意可以斜着连通. 解题思路: 八个方向dfs一遍,一边df ...
- DFS(连通块) ZOJ 2743 Bubble Shooter
题目传送门 题意:从炮台射出一个球,三个及以上颜色相同的会掉落,问最后会掉落多少个球 分析:先从炮台找一个连通块,然后与顶部连接的连通块都不会掉落,剩下的就是炮台射出后跟随掉落的. #include ...
- Codeforces Round #375 (Div. 2)——D. Lakes in Berland(DFS连通块)
D. Lakes in Berland time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 5 - C. The Labyrinth (dfs联通块操作)
题目链接:http://codeforces.com/contest/616/problem/C 题意就是 给你一个n行m列的图,让你求’*‘这个元素上下左右相连的连续的’.‘有多少(本身也算一个), ...
- HDU 1241 DFS
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- HDU - 1241 dfs or bfs [kuangbin带你飞]专题一
8个方向求联通块,经典问题. AC代码 #include<cstdio> #include<cstring> #include<algorithm> #includ ...
- hdu 1241(DFS/BFS)
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- P1141 01迷宫 dfs连通块
题目描述 有一个仅由数字000与111组成的n×nn \times nn×n格迷宫.若你位于一格0上,那么你可以移动到相邻444格中的某一格111上,同样若你位于一格1上,那么你可以移动到相邻444格 ...
随机推荐
- C++专题 - 面向对象总结
1. 什么是类?什么是对象?对象与类的关系是什么? 答:类就是相同的数据和相同的一组对象的集合,即类是对具有相同数据结构和相同操作的一类对象的描述: 对象是描述其属性的数据以及对这些数 ...
- Lucene初步搜索
Lucene在创立索引后,要进行搜索查询 搜索大概需要5部, 1,读取索引. 2,查询索引. 3,匹配数据. 4,封装匹配结果. 5,获取需要的值. 语言表达能力不好,大概就是分着几部吧. /** * ...
- libctemplate——C语言模块引擎简介及使用
前言 由先声明此libctemplate不是Google那个ctemplate.这个库是用C语言实现的,只有一个实现文件和一个头文件.Gooogl的ctemplate是C++实现的,和线程还扯上了关系 ...
- 基于matlab的GUI界面开发软件
matlab工具deploytool编译M为可执行程序 http://blog.sina.com.cn/s/blog_60f8483a0100gnsm.html
- QTableView使用自定义委托(QItemDelegate)
需要在表格中绘制流程图,主要有箭头,方向,颜色,字符串,由于QTableView没有可用的绘制函数,所以需要自己去定义. 委托(delegate)继承QItemDelegate,模型(model)继承 ...
- 精通 Oracle+Python,第 4 部分:事务和大型对象
通过 Python 管理数据事务.处理大型对象 2010 年 3 月发布 事务包含一组 SQL 语句,这组 SQL 语句构成数据库中的一个逻辑操作,如转帐或信用卡支付操作.将 SQL 语句聚合到一个逻 ...
- 异步请求HTTP
代码: @interface HttpProcessor : NSObject <NSURLConnectionDataDelegate> { NSMutableData *buffer; ...
- python使用__future__
Python的新版本会引入新的功能,但是,实际上这些功能在上一个老版本中就已经存在了.要“试用”某一新的特性,就可以通过导入__future__模块的某些功能来实现. 例如,Python 2.7的整数 ...
- 【MyBatis学习笔记】
[MyBatis学习笔记]系列之预备篇一:ant的下载与安装 [MyBatis学习笔记]系列之预备篇二:ant入门示例 [MyBatis学习笔记]系列之一:MyBatis入门示例 [MyBatis学习 ...
- 客户端(C#)调用CXF搭建的webservice的出现一些问题记录
最近把XFire框架搭建的一个webservice换成CXF框架.访问webservice的客户端是C#写的.客户端调用webservice,数据能在客户端得到.看起来显然是成功了. 但其中在VS中添 ...