POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)
来之不易的2017第一发ac
http://poj.org/problem?id=2386
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 31474 | Accepted: 15724 |
Description
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.
- import java.util.Scanner;
- public class Main{
- int n,m;
- static int N = 105, M =105;
- static char field[][] = new char[N][M];
- static int res = 0;
- static void dfs(int x, int y) {
- field[x][y] = '.';
- for(int dx=-1;dx<=1;dx++)
- for(int dy=-1;dy<=1;dy++)
- {
- int nx=x+dx;
- int ny=y+dy;
- if(nx>=0&&nx<N&&ny>=0&&ny<M&&(field[nx][ny]=='W'))
- dfs(nx,ny);
- }
- return;
- }
- public static void main(String[] args) {
- Scanner cin = new Scanner(System.in);
- N=cin.nextInt();
- M=cin.nextInt();
- String s;
- for(int i=0;i<N;i++){
- s = cin.next();
- for(int j=0;j<M;j++)
- field[i][j]=s.charAt(j);
- }
- for(int i=0;i<N;i++){
- for(int j=0;j<M;j++){
- if(field[i][j]=='W'){
- dfs(i,j);
- res++;
- }
- }
- }
- System.out.println(res);
- cin.close();
- }
- }
POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)的更多相关文章
- [POJ 2386] Lake Counting(DFS)
Lake Counting Description Due to recent rains, water has pooled in various places in Farmer John's f ...
- Lake Counting(DFS连通图)
Description Due to recent rains, water has pooled in various places in Farmer John's field, which is ...
- POJ 2386 Lake Counting DFS水水
http://poj.org/problem?id=2386 题目大意: 有一个大小为N*M的园子,雨后积起了水.八连通的积水被认为是连接在一起的.请求出院子里共有多少水洼? 思路: 水题~直接DFS ...
- Lake Counting (DFS)
N*M的园子,雨后积起了水.八连通的积水背认为是连接在一起的.请求出园子里总共有多少水洼? dfs(Depth-First Search) 八个方向的简单搜索.... 深度优先搜索从最开始的状态出 ...
- 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 ...
- 【POJ - 2386】Lake Counting (dfs+染色)
-->Lake Counting 直接上中文了 Descriptions: 由于近日阴雨连天,约翰的农场中中积水汇聚成一个个不同的池塘,农场可以用 N x M (1 <= N <= ...
- POJ:2386 Lake Counting(dfs)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 40370 Accepted: 20015 D ...
- poj 2386:Lake Counting(简单DFS深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 18201 Accepted: 9192 De ...
随机推荐
- mssql 字增自段怎样重置(重新自增)|清空表已有数据
方法1 -- 清空已有数据,并且将自增自段恢复从1开始计数 truncate table 表名 方法2 -- 不清空已有数据,但将自增自段恢复从1开始计数 dbcc checkident(表名,RES ...
- 你真的会玩SQL吗?透视转换的艺术
你真的会玩SQL吗?系列目录 你真的会玩SQL吗?之逻辑查询处理阶段 你真的会玩SQL吗?和平大使 内连接.外连接 你真的会玩SQL吗?三范式.数据完整性 你真的会玩SQL吗?查询指定节点及其所有父节 ...
- 跨域之jsonp
我们都知道使用<script>标签可以引入外部的JS文件,即使这个JS文件来自于其他的网站,比如我们引用存放在网络服务器上的jQuery框架.在这个过程中,我们已经实现跨域访问.像< ...
- FFmpeg学习3:播放音频
参考dranger tutorial,本文将介绍如何使用FFmpeg解码音频数据,并使用SDL将解码后的数据输出. 本文主要包含以下几方面的内容: 关于播放音频的需要的一些基础知识介绍 使用SDL2播 ...
- SSM项目搭建(提供源码)
1创建web动态项目,项目结构截图 2.配置日志文件 #\u5B9A\u4E49LOG\u8F93\u51FA\u7EA7\u522B log4j.rootLogger=INFO,Console,Fi ...
- 打造高效前端工作环境 - tmux
打造高效前端工作环境 - tmux 前言 现在前端开发可不容易啊,先打开个VIM,然后再打开个lite-server,一不小心写个ES2015还要打开个gulp来做预编译,如果能把这么多个窗口放在一 ...
- 解决MyEclipe出现An error has occurred,See error log for more details的错误
今晚在卸载MyEclipse时出现An error has occurred,See error log for more details的错误,打开相应路径下的文件查看得如下: !SESSION 2 ...
- reStructuredText(rst)快速入门语法说明
reStructuredText 是扩展名为.rst的纯文本文件,含义为"重新构建的文本"",也被简称为:RST或reST:是Python编程语言的Docutils项目的 ...
- c#面向对象基础技能——学习笔记(五)委托技术在开发中的应用
委托 delegate 1.是一种全新的面向对象语言的特性: 2.开发事件驱动程序变得非常简单: 3.简化多线程难度. 理解委托:可以理解成一个方法的指针.(接收的变量是方法) 步骤: 1.声明委托, ...
- C#开发微信门户及应用(36)--微信卡劵管理的封装操作
前面几篇介绍了微信支付方面的内容,本篇继续微信接口的一些其他方面的内容:卡劵管理.卡劵管理是微信接口里面非常复杂的一个部分,里面的接口非常多,我花了不少时间对它进行了封装处理,重构优化等等工作,卡劵在 ...