bzoj1751 [Usaco2005 qua]Lake Counting
1751: [Usaco2005 qua]Lake Counting
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 168 Solved: 130
[Submit][Status]
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
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
OUTPUT DETAILS:
There are three ponds: one in the upper left, one in the lower left,
and one along the right side.
省队集训上午的比赛又放弃治疗了……去刷刷水题来找回继续听课的勇气
#include<cstdio>
#include<iostream>
using namespace std;
const int mx[8]={1,1,1,0,0,-1,-1,-1};
const int my[8]={1,0,-1,1,-1,1,0,-1};
int n,m,ans;
int map[110][110];
void dfs(int x,int y)
{
map[x][y]=0;
for (int k=0;k<8;k++)
{
int nx=mx[k]+x;
int ny=my[k]+y;
if (map[nx][ny]) dfs(nx,ny);
}
}
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
{
char ch;
cin>>ch;
if (ch=='W')map[i][j]=1;
}
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
if(map[i][j]){dfs(i,j);ans++;}
printf("%d",ans);
}
bzoj1751 [Usaco2005 qua]Lake Counting的更多相关文章
- 1751: [Usaco2005 qua]Lake Counting
1751: [Usaco2005 qua]Lake Counting Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 190 Solved: 150[Su ...
- POJ_2386 Lake Counting (dfs 错了一个负号找了一上午)
来之不易的2017第一发ac http://poj.org/problem?id=2386 Lake Counting Time Limit: 1000MS Memory Limit: 65536 ...
- 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 ...
- BZOJ1754: [Usaco2005 qua]Bull Math
1754: [Usaco2005 qua]Bull Math Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 374 Solved: 227[Submit ...
- BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁
2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 56 Solved: 16[S ...
- BZOJ 3385: [Usaco2004 Nov]Lake Counting 数池塘
题目 3385: [Usaco2004 Nov]Lake Counting 数池塘 Time Limit: 1 Sec Memory Limit: 128 MB Description 农夫 ...
- 1755: [Usaco2005 qua]Bank Interest
1755: [Usaco2005 qua]Bank Interest Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 187 Solved: 162[Su ...
- 1753: [Usaco2005 qua]Who's in the Middle
1753: [Usaco2005 qua]Who's in the Middle Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 290 Solved: ...
随机推荐
- MVC4.0系统开发新手历程(三)---数据导入计算
数据导入计算 数据的重要意义就不需要我多说了吧,本项目中的数据来源是来自荆艺系统(熟悉物流报关的朋友应该知道)导出的一张Excel,包含了一段时间内整个公司所有销售的全部记录,保密级别那是杠杠的, ...
- java开发经验分享(一)
一. 编码 1. 约束自己,规范编码习惯 充足的代码注释.标准缩进的格式.注意命名规范.参考<开发管理规范> "看上去"专业能促进代码质量.越是难看的代码,在它的演化过 ...
- 模仿TMALL搜索,下拉提示 优化 用户keypress停顿200毫秒间隔时,在执行异步取数据操作 通过underscore的函数debounce来实现
- ShellSort Shell排序
希尔排序(Shell Sort)又称为“缩小增量排序”.是1959年由D.L.Shell提出来的.该方法的基本思想是:先将整个待排元素序列分割成若干个子序列(由相隔某个“增量”的元素组成的)分别进行直 ...
- (转)iOS7界面设计规范(9) - UI基础 - 动画
傍晚下了场大雨,现在坐在屋里也真是很风凉,听着Everlong突然觉得好像去年秋天的气息.每个季节都有各自的气息,每一年也是,如果你留意,便会感觉到.话说这几天,外面的猫猫狗狗们可以补些水来喝了,这也 ...
- (转载)XML Tutorial for iOS: How To Choose The Best XML Parser for Your iPhone Project
There are a lot of options when it comes to parsing XML on the iPhone. The iPhone SDK comes with two ...
- zoj 3547 The Boss on Mars
需要用到概率论的容斥定理以及计算1 ^ 4 + 2 ^ 4 + ……+ n ^ 4的计算公式1^4+2^4+……+n^4=n(n+1)(2n+1)(3n^2+3n-1)/30 #pragma comm ...
- CFGYM 2013-2014 CT S01E03 D题 费用流模版题
题意: n行, a房间的气球,b房间的气球 i行需要的气球,与a房的距离,b房的距离 求最小距离 #include <stdio.h> #include <string.h> ...
- Internetmap.apk实现原理分析
1.本地实现调用 程序根据data文件目录下的asinfo.json文件(包含自治域网络名和对应的坐标值),调用so文件绘制asn结点图(ASN,AutoSystemNode,自治域结点) 2.路由查 ...
- Android AsyncTask学习
Android程序有UI进程和后台进程,在执行一些耗时的操作时,如果在UI进程中,很可能出现假死的情况,用户体验会受到影响,因此,那些耗时进程往往就放在了后台进程中,用户体验能更好一些.网络情况不稳定 ...