【首先膜拜大湿】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 ...
随机推荐
- git学习,什么是git?
什么是 Git? 百度百科显示,Git是 Linux 之父 Linus Trovalds,为管理 Linux 内核代码而建立的,被认为是分布式版本控制工具中的顶级水准.智能.友好.强健.高效. 正如所 ...
- WWDC2014 debugging_in_xcode_6 总结
1.GCD的waiting queue 可以在Xcode左侧的面板中查看. 2.可以对View进行debug类似reveal. 3.查看运行时的对象,对于自定义对象可以实现- (id)debugQui ...
- 项目分析(channelid是如果产生的)
channelid如何生成的 /////////////////////////////////////////////////////////////// // // I_TCPServer.h / ...
- API文档管理工具-数据库表结构思考.
API文档管理工具-数据库表结构思考. PS: 管理工具只是为了方便自己记录API的一些基本信息,方便不同的开发人员 (App Developer, Restful API Developer)之间的 ...
- Nodejs Express 4.X 中文API 1--- Application篇
相关阅读: Express 4.X API 翻译[一] -- Application篇 Express4.XApi 翻译[二] -- Request篇 Express4.XApi 翻译[三] -- ...
- 腾讯开源的轻量级CSS3动画库:JX.Animate
JX.Animate 是由腾讯前端团队 AlloyTeam 推出的一个 CSS3 动画库,通过 JX(腾讯的前端框架)插件的形式提供. Why CSS3 众所周知在支持HTML5的浏览器中 ...
- 如何做到尽可能不使用庞大的jQuery
jQuery 是现在最流行的 JavaScript 工具库. 据统计,目前全世界 57.3% 的网站使用它.也就是说,10 个网站里面,有 6 个使用 jQuery.如果只考察使用工具库的网站,这个比 ...
- 对于Linux平台下C语言开发中__sync_函数的认识
reference:http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html#Atomic-Builtins A built ...
- NodeJS异常处理uncaughtException篇
很多 NodeJS 的开发者在抱怨异常处理太麻烦,我们会通过一些列博客梳理一下NodeJS中常见的异常处理的手段. 和大多数编程语言一样,在 NodeJS 里可以通过throw抛出一个异常: thro ...
- POJ 2513 Colored Sticks (离散化+并查集+欧拉通路)
下面两个写得很清楚了,就不在赘述. http://blog.sina.com.cn/s/blog_5cd4cccf0100apd1.htmlhttp://www.cnblogs.com/lyy2890 ...