2011

2023-05-16

2011

Problem Description
The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a grid that divides the land into numerous square plots. It then analyzes each plot separately, using sensing equipment to determine whether or not the plot contains oil. A plot containing oil is called a pocket. If two pockets are adjacent, then they are part of the same oil deposit. Oil deposits can be quite large and may contain numerous pockets. Your job is to determine how many different oil deposits are contained in a grid. <br>
 

Input
The input file contains one or more grids. Each grid begins with a line containing m and n, the number of rows and columns in the grid, separated by a single space. If m = 0 it signals the end of the input; otherwise 1 <= m <= 100 and 1 <= n <= 100. Following this are m lines of n characters each (not counting the end-of-line characters). Each character corresponds to one plot, and is either `*', representing the absence of oil, or `@', representing an oil pocket.<br>
 

Output
For each grid, output the number of distinct oil deposits. Two different pockets are part of the same oil deposit if they are adjacent horizontally, vertically, or diagonally. An oil deposit will not contain more than 100 pockets.<br>
 

Sample Input

  
  
1 1<br>*<br>3 5<br>*@*@*<br>**@**<br>*@*@*<br>1 8<br>@@****@*<br>5 5 <br>****@<br>*@@*@<br>*@**@<br>@@@*@<br>@@**@<br>0 0 <br>
 

Sample Output

  
  
0<br>1<br>2<br>2<br>
 

Source
Mid-Central USA 1997
题意:给出一幅地图,判断相邻,对角的油田有多少个

思路:根据题意可知,需要使用搜索算法。其实这题BFS和DFS应该都可以,最后采用了深搜。深搜的代码如下:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<cstdlib>
#include<string>
using namespace std; 
typedef long long ll;
const double pi=acos(-1.0);
char s[120][120];
int a[8]={-1,-1,0,1,1,1,0,-1};
int b[8]={0,1,1,1,0,-1,-1,-1};
void dfs(int i,int j){
	if(i<0 || j<0)
		return;
	if(s[i][j]=='@'){
		s[i][j]='*';
		for(int k=0;k<8;k++)
			dfs(i+a[k],j+b[k]);
	}
}

int main(){
	int m,n;
	while(scanf("%d%d",&m,&n)!=EOF && (m||n)){
		int i,j;
		for(i=0;i<m;i++)
			scanf("%s",s[i]);
		int ans=0;
		for(i=0;i<m;i++){
			for(j=0;j<n;j++){
				if(s[i][j]=='@'){
					ans++;
					dfs(i,j);
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

2011 的相关文章

  • 2011,我和CSDN亲密接触的一年

    从CSDN刚刚发出这次征文活动的时候 xff0c 就有一种想参加的冲动 xff0c 总想说些什么 xff0c 迟迟直到今天才开始下笔 和大家一样 xff0c 我也是一名普通的计算机研发人员 xff0c 说挨踢者也行 xff0c 说码农亦可
  • 2011

    2011 Problem Description The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits G
  • ITIL 2011 -- 服务运营的5个流程简介 (上)

    要做一个IT运维管理的项目 xff0c 客户提到了ITIL xff08 IT Infrastructure Library xff09 xff0c 所以谈需求之前我研究了一下ITIL xff0c 发现东西比较多 xff0c 但是里面的服务运
  • Luogu 3631 [APIO 2011] 方格染色

    传送门思路参考代码细节 传送门 思路 很不错的一道题 xff0c 用到的东西不深 xff0c 但是要想到确实需要一定思维 一开始我想的是动态规划 xff0c 发现如果要设状态需要知道一个格子左边 xff0c 上边和左上边三个格子的状态 然后
  • Luogu 3632 [APIO 2011] 寻路

    传送门正解参考代码 传送门 正解 暴力连边跑最短路就好了 xff0c 只不过代码太长太难写啦 xff01 参考代码 span class hljs preprocessor include lt cstdio gt span span cl
  • 2011/11/26

    听雨听风听愁绵 xff0c 疏雨薄衣心无涟
  • 【无人机】【2011.03】无人飞行器的自主飞行研究

    本文为澳大利亚悉尼大学 xff08 作者 xff1a Nicholas R J Lawrance xff09 的博士论文 xff0c 共233页 无人机 xff08 UAV xff09 在一系列工业 科学和国防应用中提供了独特的能力 小型无
  • 纪事2011—中国,建大,家,我

    前言 2011 年就要真的成为我记忆了 xff0c 我一直在想该怎样总结我的2011 xff0c 我的2011留下的是什么 xff0c 收获的又是什么 xff0c 这365天的句号我该怎么画上 xff0c 是圆是扁 xff0c 还是有缺口
  • 我的2011 憧憬2012

    逝者如斯夫 不舍昼夜 2012已经向我们走来 xff0c 我们面对2011的离开 xff0c 稍有不舍 xff1b 但是人总得往前走 xff0c 微笑迎接2012 xff0c 注定我们在2012收获的更多 2011 xff0c 写给宿舍的哥
  • CentOS8.3.2011无法联网解决方案

    1 切换到ifcfg ensXX目录下 cd etc sysconfig network scripts 2 编辑ifcfg ensXX文件 vim ifcfg ens33 3 修改 BOOTPROTO 61 dhcp 并且修改 ONBOO
  • 写下2011,展望2012

    一年又过去了 xff0c 好快 xff0c 写个总结 xff0c 也算是对这一年有个交代吧 一 上半年 xff1a 专心科研 总的来说 xff0c 上半年还是过得比较惬意的 xff0c 安心做科研 xff0c 主要还是做wince 嵌入式开
  • 2011-2012中国嵌入式开发从业人员调查报告

    调查背景 在今天所处的大时代背景下 xff0c 嵌入式 3G移动互联网 物联网 云计算俨然已成为信息产业的主旋律 xff0c 不管从政府大力扶持角度来看 xff0c 还是从产业变革的主流方向来说 xff0c 这股潮流早已势不可挡 而嵌入式系
  • 我的2011--人生转折点

    恍然 xff0c 2011 12 30了 xff0c 这一年又将过去 xff01 回首这一年 xff0c 感觉是我生命中成长最快的一年 年初到年末 xff0c 好像是一个质的跨越 在即将过去的2011最后的时间里 xff0c 写下这边blo
  • 2011,我和CSDN亲密接触的一年

    从CSDN刚刚发出这次征文活动的时候 xff0c 就有一种想参加的冲动 xff0c 总想说些什么 xff0c 迟迟直到今天才开始下笔 和大家一样 xff0c 我也是一名普通的计算机研发人员 xff0c 说挨踢者也行 xff0c 说码农亦可
  • ---------------------------谨以此文献给我的2011-----------------------------------

    2011年就快过去了 xff0c 回首我的2011 xff0c 有收获 xff0c 也有失落 xff0c 有胜利 xff0c 也有失败 有高兴的事情 xff0c 也有很多不高兴的事情 如果说往事不堪回首来总结的话 xff0c 未免有点太过于
  • 再见2011,你好,2012。

    不会写文章 xff0c 这个算是对自己的一个总结吧 xff0c 毕业一年半了 xff0c 从事嵌入式也有一年半了 xff0c 总觉得自己连入门都谈不上 xff0c 整天都看上去很忙 xff0c 有时候确实有一大堆的事情要做 xff0c 但是
  • 我的2011----再见2011!你好2012!

    今天本来是 特别平常的一天 但是因为位置排在了 2011 年的最后 平常也就变得不平常了 一年就在这么转眼即逝中度过了 虽说一年比较短暂 但是回头在看看自己所拥有的这一年 留下的很多 在 2011 我把 ShortBrain 英语进行着 英
  • 写在2011

    很早就想写点东西了 xff0c 可晃荡晃荡地就到了2011年最后一刻 我想是要写点东西了 2011年 xff0c 我有太多的感触 这一年是我第一次在异地迎接农历新年了 xff0c 对 xff0c 当时的感觉很刺激 xff0c 刺激得让我和当
  • BW笔记(2011-10-24更新至No.237)

    1 同一个变量名的UID可能有多个 xff0c 记得注意 2 在查找时要注意技术名称还是名称 xff0c 因为查询时会在两个中进行 xff0c 模糊查询时要细心 xff0c FV与V都可以查到 3 复制的时候注意长度 xff0c 过长的会不
  • 2011年北京大学计算机研究生机试真题(题解)

    九度OJ题目传送门 2011年北京大学计算机研究生机试真题 鸡兔同笼 题目描述 一个笼子里面关了鸡和兔子 鸡有2只脚 兔子有4只脚 没有例外 已经知道了笼子里面脚的总数a 问笼子里面至少有多少只动物 至多有多少只动物 输入 第1行是测试数据

随机推荐