POJ2386 Lake Counting 【DFS】
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 20782 | Accepted: 10473 |
Description
out how many ponds have formed in his field. A pond is a connected set of squares with water in them, where a square is considered adjacent to all eight of its neighbors.
Given a diagram of Farmer John's field, determine how many ponds he has.
Input
* Lines 2..N+1: M characters per line representing one row of Farmer John's field. Each character is either 'W' or '.'. The characters do not have spaces between them.
Output
Sample Input
- 10 12
- W........WW.
- .WWW.....WWW
- ....WW...WW.
- .........WW.
- .........W..
- ..W......W..
- .W.W.....WW.
- W.W.W.....W.
- .W.W......W.
- ..W.......W.
Sample Output
- 3
Hint
There are three ponds: one in the upper left, one in the lower left,and one along the right side.
Source
睡前水一水。
- #include <stdio.h>
- #include <string.h>
- #define maxn 102
- char G[maxn][maxn];
- int n, m;
- const int mov[][2] = {0, 1, 0, -1, 1, 0, -1,
- 0, 1, -1, -1, 1, 1, 1, -1, -1};
- void DFS(int x, int y) {
- G[x][y] = '.';
- int i, j, nx, ny;
- for(i = 0; i < 8; ++i) {
- nx = x + mov[i][0];
- ny = y + mov[i][1];
- if(nx >= 0 && nx < n && ny >= 0 && ny < m && G[nx][ny] == 'W')
- DFS(nx, ny);
- }
- }
- int main() {
- int i, j, ret;
- while(scanf("%d%d", &n, &m) == 2) {
- for(i = 0; i < n; ++i)
- scanf("%s", G[i]);
- ret = 0;
- for(i = 0; i < n; ++i)
- for(j = 0; j < m; ++j)
- if(G[i][j] == 'W') {
- DFS(i, j);
- ++ret;
- }
- printf("%d\n", ret);
- }
- return 0;
- }
POJ2386 Lake Counting 【DFS】的更多相关文章
- Openjudge1388 Lake Counting【DFS/Flood Fill】
http://blog.csdn.net/c20182030/article/details/52327948 1388:Lake Counting 总时间限制: 1000ms 内存限制: ...
- Poj2386 Lake Counting (DFS)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 49414 Accepted: 24273 D ...
- CF990G-GCD Counting【dfs】
正题 题目链接:https://www.luogu.com.cn/problem/CF990G 题目大意 给出一棵有点权的树,对于每个\(k\)求有多条路径的点权\(gcd\)为\(k\) \(1\l ...
- POJ 2386 Lake Counting【BFS】
题意:给出一个矩形,问有多少块连通的W 当找到W的时候,进行广搜,然后将搜过的W变成点,直到不能再搜,进行下一次广搜,最后搜的次数即为水塘的个数 看的PPT里面讲的是种子填充法. 种子填充算法: 从多 ...
- 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】
目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...
- Kattis - glitchbot 【DFS】
Kattis - glitchbot [DFS] 题意 有一个机器人 刚开始在(0, 0),然后给出一个目标点,并且会给出一系列指令,但是其中会有一个指令是错误的.我们需要找出那个指令,并且改成正确的 ...
- HDU 6113 度度熊的01世界 【DFS】(2017"百度之星"程序设计大赛 - 初赛(A))
度度熊的01世界 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- 【POJ - 2386】Lake Counting (dfs+染色)
-->Lake Counting 直接上中文了 Descriptions: 由于近日阴雨连天,约翰的农场中中积水汇聚成一个个不同的池塘,农场可以用 N x M (1 <= N <= ...
- 【dfs】POJ2386湖计数
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 34735 Accepted: 17246 D ...
随机推荐
- python - unittest - 单元测试
# -*- coding:utf-8 -*- '''@project: jiaxy@author: Jimmy@file: study_unittest.py@ide: PyCharm Communi ...
- PTA 11-散列4 Hard Version (30分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/680 5-18 Hashing - Hard Version (30分) Given ...
- PHP允许AJAX跨域请求的两种方法
* 一. 服务端设置 header 头允许AJAX跨域 ** 代码如下: // 允许 ityangs.net 发起的跨域请求 header("Access-Control-Allow-Ori ...
- 设计模式(八)组合模式 Composite
组合模式: 允许你将对象组合成树形结构来表现“整体/部分”层次结构.组合能让客户以一致的方式处理个别对象以及对象组合. 组合模式适用于创建复杂的对象,这个对象包含某些个别的对象以及这些对象的组合. 从 ...
- python 缺少包
https://pypi.python.org/pypi/pdfminer/20140328 到这里下载相应的包,再进行安装. tar –xivf pybloomfilter-1.0 cd py ...
- java面试题之你了解守护线程吗?它和非守护线程有什么区别
程序运行完毕,jvm会等待非守护线程完成后关闭,但是jvm不会等待守护线程. 守护线程最典型的的例子是:GC线程
- mybatis读取oracle中blob
controller: byte[] blob = commonService.getPersonImage(bean.getIdCard()); String base64 = new String ...
- javaweb之Filter详解
一.概念:Filter也称之为过滤器,它是Servlet技术中比较激动人心的技术,WEB开发人员通过Filter技术,对web服务器管理的所有web资源:例如Jsp, Servlet, 静态图片文件或 ...
- ace模板dataTables_length控制是否显示分页
默认的ace中配置的是7列之后才显示分页的,其实是可控的,如下: aoColumns这个参数的含义: 排序控制 $(document).ready(function() {$('#example'). ...
- 慕课爬虫实战 爬取百度百科Python词条相关1000个页面数据
http://www.imooc.com/learn/563 spider_main.py #!/usr/bin/python # coding=utf-8 #from baike_spider im ...