当前位置: 首页 > news >正文

温岭自适应网站建设/百度网页版电脑版入口

温岭自适应网站建设,百度网页版电脑版入口,茂名做网站公司,免费网站设计工具转载请注明出处:https://blog.csdn.net/Mercury_Lc/article/details/82706189 作者:Mercury_Lc 题目链接 题解:每个点(为被修改,是#)进行一次dfs,每次dfs到的点,也就是八个方向都将…

转载请注明出处:https://blog.csdn.net/Mercury_Lc/article/details/82706189   作者:Mercury_Lc

题目链接

题解:每个点(为被修改,是#)进行一次dfs,每次dfs到的点,也就是八个方向都将  '#'  修改成  '*',下次dfs就不用再搜索这一点了,因为已经确定这个点和前面的点是一个部分,这样遍历一遍图,如果可以dfs(i,j),ans++,最后ans就是答案了。当然也可以用bfs思路来想(点一下我QWQ)。

#include <bits/stdc++.h>using namespace std;const int maxn = 1e3;
int n,m;
char gra[maxn][maxn];
int dx[] = {1,1,1,-1,-1,-1,0,0};
int dy[] = {0,1,-1,1,0,-1,1,-1};
void dfs(int i, int j)
{gra[i][j] = '*';for(int k = 0; k < 8; k ++){int tx = dx[k] + i;int ty = dy[k] + j;if(tx >= 0 && tx < n && ty >= 0 && ty < m && gra[tx][ty] == '@'){dfs(tx,ty);}}
}
int main()
{int ans = 0;while(~scanf("%d %d",&n,&m)&&n&&m){ans = 0;for(int i = 0; i < n; i ++){getchar();scanf("%s",gra[i]);}for(int i =0; i < n; i ++){for(int j = 0; j < m; j ++){if(gra[i][j] == '@'){dfs(i,j);ans ++;}}}printf("%d\n",ans);}return 0;
}

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.

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.

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.

Sample Input

1 1
*
3 5
*@*@*
**@**
*@*@*
1 8
@@****@*
5 5 
****@
*@@*@
*@**@
@@@*@
@@**@
0 0 

Sample Output

0
1
2
2

转载于:https://www.cnblogs.com/lcchy/p/10139520.html

http://www.lbrq.cn/news/1620847.html

相关文章:

  • 门户网站建设滞后/郑州网络运营培训
  • 阳江网站制作公司/每日精选12条新闻
  • 宁波网站建设公司网络推广/外链吧怎么使用
  • cms网站开发毕设/成都网站排名 生客seo
  • 网站制作软件安卓版/seo内容优化心得
  • 江苏城嘉建设工程有限公司网站/营销网站建设哪家快
  • 公司做网站的多吗/怎样做一个网页
  • b2b网站做推广什么网站好/徐州新站百度快照优化
  • 电话做网站的推广/新站如何快速收录
  • 网站开发量/株洲网站设计外包首选
  • 外国网站界面/it培训学校哪家好
  • 广州智能模板建站/最好的网站设计公司
  • 永久免费自动建站系统/今日国际新闻最新消息大事
  • 网站可以做被告嘛/国内比较好的软文网站
  • 哪个网站可以做创意短视频网站/加入网络营销公司
  • 银川网站建设哪家优/sem培训班学费哪个好
  • 湛江制作网站多少钱/热狗seo优化外包
  • 做网站 什么语言/想要推广网页正式版
  • 拍卖网站建设/合肥网站推广
  • 温州网站建设和推广/安卓优化大师最新版
  • 做网站用什么/网站搜索
  • 学生做网站的目的/怎样做网站
  • 音乐网站设计总结/参考消息今天新闻
  • 手机端企业网站怎么做/网络推广怎么做方案
  • w网站怎么做/海南seo顾问服务
  • wordpress如何修改页脚/合肥网站推广优化公司
  • 提供免费网站建设/互联网培训机构排名前十
  • 建一个公司需要多少钱/怎么优化整站
  • 网站频道建设/seo网站排名全选
  • 大良营销网站建设流程/深圳网站营销seo电话
  • pytorch小记(三十三):PyTorch 使用 TensorBoard 可视化训练过程(含完整示例)
  • Wndows Docker Desktop-Unexpected WSL error错误
  • leaflet中绘制轨迹线的大量轨迹点,解决大量 marker 绑定 tooltip 同时显示导致的性能问题
  • 文件操作与IO流
  • Excel制作滑珠图、哑铃图
  • 机器学习线性回归:从基础到实践的入门指南