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 ...
随机推荐
- ASP.NET MVC5+EF6+EasyUI 后台管理系统(41)-组织架构
系列目录 本节开始我们要实现工作流,此工作流可以和之前的所有章节脱离关系,也可以紧密合并. 我们当初设计的项目解决方案就是可伸缩可以拆离,可共享的项目解决方案.所以我们同时要添加App.Flow文件夹 ...
- JQuery 加载 CSS、JS 文件
JS 方式加载 CSS.JS 文件: //加载 css 文件 function includeCss(filename) { var head = document.getElementsByTagN ...
- Linux下的磁盘分割和文件系统
一.各硬件装置在Linux下的文件名 1.IDE硬盘机 在Linux内的文件名: /dev/hd[a-d] (a-d 刚好是四个这个是有原因的具体如下) 解释:以 IDE 接口来说,由于一个 IDE ...
- [深入JUnit] 测试运行的入口
阅读前提 了解JUnit 对JUnit的内部实现有兴趣 不妨看看[深入JUnit] @Before, @After, @Test的秘密] 代码版本: junit 4.12代码搜索工具: http:// ...
- Lua BehaviourTree 各节点说明
项目说明 本行为树的代码使用Lua编写,所有的内容也建立的Lua的基础语法之上 因为公司项目需求,需要一套Lua的行为树代码,所以尝试从饥荒中抽离了行为树相关的代码.绝大多数节点行为与饥荒中相同,不过 ...
- iOS学习笔记——滚动视图(scrollView)
滚动视图:在根视图中添加UIScrollViewDelegate协议,声明一些对象属性 @interface BoViewController : UIViewController<UIScro ...
- [函數] Firemonkey Android 取得系统参数设定的字型大小
Android 系统参数设定内,可以设定字型大小: 可以透过下面代码来取得字型大小比例: function FontScale: Single; var Resources: JResources; ...
- Java的内存分配
java内存分配 A:栈 存储局部变量 B:堆 存储所有new出来的 C:方法区(方法区的内存中) 类加载时 方法信息保存在一块称为方法区的内存中, 并不随你创建对象而随对象保存于堆中; D:本地方法 ...
- Windows安装RabbitMQ集群的几个注意点
记录一下RabbitMQ在windows平台下安装的几个注意点- -,好记性不如烂笔头 安装过程与Linux安装一致,教程参照官网集群配置:此处只列举出几个注意点: 1. erlang的版本需要一致, ...
- mui 手势事件配置
在开发中监听双击屏幕事件时不起作用,需要在mui.init方法的gestureConfig参数中设置需要监听的手势事件 手势事件配置: 根据使用频率,mui默认会监听部分手势事件,如点击.滑动事件:为 ...