poj1562--Oil Deposits
Description
Input
Output
Sample Input
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
Sample Output
0122
分析:向八个方向搜索、
源码:
#include <stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
char map[101][101];
int n, m, p;
void dfs(int i, int j)//递归函数
{
if(map[i][j]!='@' || i<0 || j<0 || i>=m || j>=n) return;
else
{
map[i][j]='*';//扫过的都变成'*'
dfs(i-1, j-1);
dfs(i-1, j);
dfs(i-1, j+1);
dfs(i, j-1);
dfs(i, j+1);
dfs(i+1, j-1);
dfs(i+1, j);
dfs(i+1, j+1);
}
}
int main()
{
int i, j;
while(scanf("%d%d",&m,&n)!=EOF)
{
if(m==0 || n==0) break;
p = 0;
for(i = 0; i < m; i++)
for(j = 0; j < n; j++)
//scanf("%c",&map[i][j]);
cin>>map[i][j];
for(i = 0; i < m; i++)
{
for(j = 0; j < n; j++)
{
if(map[i][j] == '@')
{
dfs(i, j);
p++;
}
}
}
printf("%d\n",p);
} return 0;
}
poj1562--Oil Deposits的更多相关文章
- poj1562 Oil Deposits 深搜模板题
题目描述: Description The GeoSurvComp geologic survey company is responsible for detecting underground o ...
- poj1562 Oil Deposits(DFS)
题目链接 http://poj.org/problem?id=1562 题意 输入一个m行n列的棋盘,棋盘上每个位置为'*'或者'@',求'@'的连通块有几个(连通为8连通,即上下左右,两条对角线). ...
- 暑假集训(1)第七弹 -----Oil Deposits(Poj1562)
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- 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( ...
- 2016HUAS暑假集训训练题 G - Oil Deposits
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- uva 572 oil deposits——yhx
Oil Deposits The GeoSurvComp geologic survey company is responsible for detecting underground oil d ...
- hdu 1241:Oil Deposits(DFS)
Oil Deposits Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total ...
- hdu1241 Oil Deposits
Oil Deposits Time Limit: 2000/1000 MS (Java/Others) ...
- 杭电1241 Oil Deposits
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission ...
随机推荐
- Traceroute程序
Linux和Unix中为traceroute,Windows中对应的是Tracert.如:Tracert www.baidu.com 输出为路由信息. C:\Users\Administrator ...
- Android调用系统邮件类应用的正确实现方法
Android应用开发中,很多情况下免不了要调用手机上的邮件类应用,实现邮件发送的功能,这一般是通过调用系统已有的Intent来实现的.看到网上很多邮件发送都是调用action为android.con ...
- ssh命令
使用ssh命令登陆远程系统 ssh [ip/address] -l [登陆用户名] 如: ssh www.xyz.cn -l root
- C# 大小写转换
全部大写: string upper = str.ToUpper() 全部小写: string lower = str.ToLower(); str是需要转换的字符.
- poj1094 topsort
Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 32275 Accepted: 11 ...
- The Definitive C++ Book Guide and List
学习c++的书单 转自 http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list Beginner ...
- LeetCode-Divdend two Integers
题目: Divide two integers without using multiplication, division and mod operator. 思路分析 二分法.将除数不断增倍,而结 ...
- 【Nutch2.2.1源代码分析之5】索引的基本流程
一.各个主要类之间的关系 SolrIndexerJob extends IndexerJob 1.IndexerJob:主要完成 2.SolrIndexerJob:主要完成 3.IndexUtil:主 ...
- 清除大文本中的html标签
public String clearHtmlText(String inputString) { if (StringUtils.isBlank(inputString)) { return &qu ...
- 移动web开发中遇到的一些问题收纳
1.获取滚动条的值: window.scrollY window.scrollX 桌面浏览器中想要获取滚动条的值是通过document.scrollTop和document.scrollLeft得到的 ...