TOJ1334
1334: Oil Deposits
总提交: 555 测试通过:404
描述
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.
输入
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.
输出
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.
样例输入
1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5
****@
*@@*@
*@**@
@@@*@
@@**@
0 0
样例输出
0
1
2
2
题目来源
题解:
题目意思是判断油带的数量,相邻油田属于同一油带,相邻,是指两个小正方形区域上下、左右、左上右下或左下右上同为’@’。
简单深搜。
#include<iostream>
using namespace std;
int x,y,i,j,s;
char arr[101][101];
int g[8]={0,0,1,1,1,-1,-1,-1};
int q[8]={1,-1,0,-1,1,0,1,-1};
int dfs(int a,int b)
{
if(a<0||b<0||a>=x||b>=y)return 0;
if(arr[a][b]=='*')return 0;
arr[a][b]='*';
for(int k=0;k<8;k++)
{
dfs(a+g[k],b+q[k]);
}
}
int main()
{
while(cin>>x>>y)
{
if(x==0&&y==0)break;
s=0;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
cin>>arr[i][j];
}
}
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
if(arr[i][j]=='@')
{
s++;
dfs(i,j);
}
}
}
printf("%d\n",s);
}
}
TOJ1334的更多相关文章
随机推荐
- android 测试 Monkey 和 MonkeyRunner 的使用
一.Monkey的使用 Monkey使用起来比较简单,简而言之就是模拟手机点击效果,随机发送N个点击动作给手机,主要对于程序的稳定和承受压力的测试. 1.首先连接上你的手机或者启动模拟器: 2.运行C ...
- HttpRequestUtil
package com.didichuxing.tempdirreader; import com.alibaba.fastjson.JSONObject; import java.io.Unsupp ...
- A problem about rcssserver3d
When I enter rcssserver3d to the terminal, the system told me this problem: (SimulationServer) SimCo ...
- 记AppStore 被打回的经历
在快驰已然有半年时间之久. 见证了“快货运”产品,在不断摧残的环境中成长着. 两个人,将一个产品亲手从无到有的构建,有过心酸.有过累和有过憔悴,但当“快货运”开始上APP store时,又让人觉得开 ...
- mvc 传递匿名对象
Controller代码: public ActionResult TupleTest() { LinqDBEntities db = new LinqDBEntities(); dynamic da ...
- C#在数据层过滤属性中的主键
C#使用泛型+反射做为数据层时,一个很都头疼的问题,如何让C#属性在程序里识别出哪个属性是主键,在拼接SQL时,不能把主键拼接到SQL语句里. 这个需要自定义一个属性.新建一个类文件,命名为Prosp ...
- HTML、CSS、JS在前端开发中都扮演怎样的角色
前端开发,需要经常接触 HTML.DOM.CSS.JS等,那么HTML.CSS.JS在前端开发中究竟扮演怎样的角色呢?以下是个人的一些观点... HTML:超文本标记语言 (Hyper Text Ma ...
- iOS一些常用的小知识点
//获取全局的Delegate对象,这样我们可以调用这个对象里的方法和变量 [[UIApplication sharedApplication] delegate]; //获得程序的主Bundle N ...
- SQL中随机数函数rand()简介
转自:http://database.51cto.com/art/201009/224397.htm 下文将为您介绍SQL中的随机函数rand(),供您参考,如果您是才接触SQL Server的新手, ...
- docker 源码分析 五(基于1.8.2版本),Docker容器的创建
前面讲到了docker容器得镜像,镜像其实是docker容器的静态部分,而docker容器则是docker镜像的动态部分,即启动了一个进程来运行,本篇最要来分析一下怎样创建并运行一个容器. 创建一个容 ...