Day2-D-Oil Deposits-POJ-1562
Input
Output
Sample Input
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
Sample Output
0
1
2
2 分析:板子题,求连通块个数,用DFS+种子填充法即可,直接给出代码:
const int maxm = ; int vis[maxm][maxm], n, m;
string G[maxm]; bool inside(int x, int y) {
return x >= && x < n && y >= && y < m;
} void dfs(int x,int y, int id) {
if(vis[x][y])
return;
vis[x][y] = id;
for(int i = -; i < ; ++i) {
for (int j = -; j < ; ++j) {
if(i || j) {
int nx = x + i, ny = y + j;
if(inside(nx,ny) && G[nx][ny] == '@' && !vis[nx][ny])
dfs(nx, ny, id);
}
} }
} int main() {
while(scanf("%d%d",&n,&m) && n+m) {
getchar();
memset(vis, , sizeof(vis));
for(int i = ; i < n; ++i)
cin >> G[i];
int sum = ;
for(int i = ; i < n; ++i) {
for(int j = ; j < m; ++j) {
if(G[i][j] == '@' && !vis[i][j])
dfs(i, j, ++sum);
}
}
printf("%d\n",sum);
}
}
Day2-D-Oil Deposits-POJ-1562的更多相关文章
- POJ 1562 && ZOJ 1709 Oil Deposits(简单DFS)
题目链接 题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket . 思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接 ...
- POJ 1562 Oil Deposits (并查集 OR DFS求联通块)
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14628 Accepted: 7972 Des ...
- [POJ] 1562 Oil Deposits (DFS)
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16655 Accepted: 8917 Des ...
- (简单) POJ 1562 Oil Deposits,BFS。
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- HDU - 1241 POJ - 1562 Oil Deposits DFS FloodFill漫水填充法求连通块问题
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil de ...
- POJ 1562:Oil Deposits
Oil Deposits Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14462 Accepted: 7875 Des ...
- Oil Deposits(poj 1526 DFS入门题)
http://poj.org/problem?id=1562 ...
- HDU 1562 Oil Deposits
题目: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. G ...
- Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tota ...
- Oil Deposits(dfs)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
随机推荐
- Web Storage API:localStorage 和 SessionStorage
Web Storage API 提供了存储机制,通过该机制,浏览器可以安全地存储键值对,比使用 cookie 更加直观. 参考:https://developer.mozilla.org/zh-CN/ ...
- CentOS7安装jenkis
注意:终止运行Ctrl+c , 退回到shell命令Ctrl+d 一.先检查是否有java [root@huangyh huangyh]# rpm -qa |grep java 或 java 因为C ...
- Http 状态码总结
HTTP 状态码列表 一. 1 开头 (继续执行) 服务器收到请求,需要请求者继续执行操作 100:(continue) 客户端继续请求 101:(Switching Protocols) 切换协议, ...
- 洛谷 CF804B Minimum number of steps
嗯... 题目链接:https://www.luogu.org/problemnew/show/CF804B 这道题没有什么技巧,只是一道找规律的题. 首先看到“ab”可以换成“bba”,所以首先要确 ...
- Qt实现通用模板单例
#include <QAtomicPointer> #include <QMutex> #include <memory> using namespace std; ...
- Python 爬取 热词并进行分类数据分析-[热词关系图+报告生成]
日期:2020.02.05 博客期:144 星期三 [本博客的代码如若要使用,请在下方评论区留言,之后再用(就是跟我说一声)] 所有相关跳转: a.[简单准备] b.[云图制作+数据导入] c.[拓扑 ...
- hbase单机版安装
hbase单机版安装 1. hbase单机版安装 HBase的安装也有三种模式:单机模式.伪分布模式和完全分布式模式. hbase依赖于Hadoop和Zookeeper. 这里安装的是单机版 ...
- 循环读取寄存器(QSFP-DD)并且分别保存log
#!/bin/bash ####################################################################### #Created by: Bin ...
- 吴裕雄 Bootstrap 前端框架开发——Bootstrap 排版:内联子标题
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- spring boot 中容器 Jetty、Tomcat、Undertow
spring boot 中依赖tomcat <dependency> <groupId>org.springframework.boot</groupId> < ...