【首先膜拜大湿】poj-2386-Lake Counting-DFS模板题
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 16802 | Accepted: 8523 |
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
题目如上:
AC代码如下:
#include<iostream>
#include<stdio.h> #define Max 105
using namespace std; char f[Max][Max];
int N ,M;
void DFS(int x,int y)
{
f[x][y] = '.';
for(int dx = -1; dx <= 1; dx++)
for(int dy = -1; dy <= 1; dy++)
{
int nx, ny;
nx = x + dx; ny = y + dy;
if(nx < N&& ny < M&& nx >= 0&& ny >= 0&&f[nx][ny] == 'W') DFS(nx,ny);
} return ;
}
int main()
{
int res = 0,i,j;
cin>>N;
cin>>M; for(i = 0; i < N; i++)
scanf("%s",&f[i]); for(int i = 0; i < N; i++)
for(int j = 0; j < M; j++)
if(f[i][j] == 'W')
{
DFS(i,j);
res++;
}
printf("%d\n",res);
}【存在的问题】1、脑残地把坐标轴坐标和矩阵的坐标对应起来了;
2、解决了以上问题后程序还是在傲娇地RE,原来还是脑残地把“=”敲成“==”了;
再后来程序还傲娇地WA了,于是
3、经大湿的指点把原输入
for(i = 0; i < N; i++)
for(j = 0; j < M; j++)
scanf("%c",&f[i][j]);
换成了
for(i = 0; i < N; i++)
scanf("%s", &f[i]);
蓝后就AC了~~o(≧v≦)o~~
原因就是%c输入把换行符给吃掉了~~蓝后造成了移位。。。。
ORZ。。。。
【首先膜拜大湿】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 ...
- POJ 2386 Lake Counting DFS水水
http://poj.org/problem?id=2386 题目大意: 有一个大小为N*M的园子,雨后积起了水.八连通的积水被认为是连接在一起的.请求出院子里共有多少水洼? 思路: 水题~直接DFS ...
- POJ 2386 Lake Counting(深搜)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17917 Accepted: 906 ...
- POJ 2386 Lake Counting
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28966 Accepted: 14505 D ...
- POJ 2386 Lake Counting(搜索联通块)
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48370 Accepted: 23775 Descr ...
- 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 ...
- POJ 2386 Lake Counting 八方向棋盘搜索
Lake Counting Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 53301 Accepted: 26062 D ...
- poj - 2386 Lake Counting && hdoj -1241Oil Deposits (简单dfs)
http://poj.org/problem?id=2386 http://acm.hdu.edu.cn/showproblem.php?pid=1241 求有多少个连通子图.复杂度都是O(n*m). ...
- POJ 2386——Lake Counting(DFS)
链接:http://poj.org/problem?id=2386 题解 #include<cstdio> #include<stack> using namespace st ...
随机推荐
- Java多jdk安装
1.安装jdk 2.配置 1.安装(略) 2.配置 2.1 regedit 注册表修改,假定已经安装jdk1.6,现在更换为jdk1.7 注: 修改红色框中CurrentVersion为jdk1.7 ...
- lca 最近公共祖先
http://poj.org/problem?id=1330 #include<cstdio> #include<cstring> #include<algorithm& ...
- 5-Highcharts曲线图之轴反转
<!DOCTYPE> <html lang='en'> <head> <title>5-Highcharts曲线图之轴反转</title> ...
- HOWTO: Create native-looking iPhone/iPad applications from HTML, CSS and JavaScript
HOWTO: Create native-looking iPhone/iPad applications from HTML, CSS and JavaScript Though it's not ...
- 10 个让人惊讶的 jQuery 插件
说是让人惊讶,你可能会觉得我们没见过世面,但这里提及的一些 jQuery 的插件的确平时比较少见,用的人应该更少. Grid portfolio 使用竖排方式显示条目信息,现在很流行的的内容布局方式. ...
- 关于trello的分享
https://www.the5fire.com/trello-share.html 昨天在公司跟同事分享了关于trello的使用,这里也分享给大家.比较简单,重点是让你知道有这么个东西.tangle ...
- Eclipse 字体选择
Windows下推荐使用Consolas Linux下推荐使用DejaVu Sans Mono, Website: http://dejavu-fonts.org/wiki/Main_PageDown ...
- Jenkins+Maven+Git CI环境搭建手册
Jenkins+Maven+Git CI环境搭建手册 环境: OS:Linux version 2.6.32-220.23.2.ali878.el6.x86_64 (ads@kbuild) (gcc ...
- Log4net学习
转自:http://www.cnblogs.com/sirkevin/archive/2012/06/13/2548449.html Log4net简介根据日志类别保存到不同的文件,并按照日期生成不同 ...
- Assembly(c#中简单说明[转]
什么是Assembly(程序集)?Assembly是一个包含来程序的名称,版本号,自我描述,文件关联关系和文件位置等信息的一个集合.在.net框架中通过Assembly类来支持,该类位于System. ...