BZOJ 3385: [Usaco2004 Nov]Lake Counting 数池塘
题目
3385: [Usaco2004 Nov]Lake Counting 数池塘
Time Limit: 1 Sec Memory Limit: 128 MB
Description
Input
Output
Sample Input
W ........ WW.
. WWW ..... WWW
.... WW ... WW.
......... WW.
......... W..
..W ...... W..
.W.W ..... WW.
W.W.W ..... W.
.W.W ...... W.
..W ....... W.
Sample Output
HINT
共有3个池塘:一个在左上角,一个在左下角,还有一个沿着右边界
题解
我用floodfill做的,呵呵,时间Rank倒数第一= =
代码
/*Author:WNJXYK*/
#include<cstdio>
#include<iostream>
using namespace std;
int n,m;
const int Maxn=;
bool map[Maxn+][Maxn+];
bool visited[Maxn+][Maxn+];
inline char read(){
char ch=getchar();
while(ch!='.' && ch!='W') ch=getchar();
return ch;
}
int cnt=;
int dx[]={,-,-,,,,,,-};
int dy[]={,,,,,,-,-,-};
void floodfill(int x,int y){
visited[x][y]=true;
for (int k=;k<=;k++){
int nx=x+dx[k],ny=y+dy[k];
if (<=nx && nx<=n && <=ny && ny<=m)
if (map[nx][ny]==true)
if (visited[nx][ny]==false)
floodfill(nx,ny);
}
} int main(){
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++){
for (int j=;j<=m;j++){
char ch=read();
if (ch=='.') map[i][j]=false;
if (ch=='W') map[i][j]=true;
visited[i][j]=false;
}
}
for (int i=;i<=n;i++){
for (int j=;j<=m;j++){
if (visited[i][j]==false&&map[i][j]==true){
floodfill(i,j);
cnt++;
}
}
}
printf("%d\n",cnt);
return ;
}
BZOJ 3385: [Usaco2004 Nov]Lake Counting 数池塘的更多相关文章
- 3385: [Usaco2004 Nov]Lake Counting 数池塘
3385: [Usaco2004 Nov]Lake Counting 数池塘 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 22 Solved: 21 ...
- BZOJ 2023 [Usaco2005 Nov]Ant Counting 数蚂蚁:dp【前缀和优化】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2023 题意: 有n个家族,共m只蚂蚁(n <= 1000, m <= 1000 ...
- bzoj 2023: [Usaco2005 Nov]Ant Counting 数蚂蚁【生成函数||dp】
用生成函数套路推一推,推完老想NTT--实际上把这个多项式乘法看成dp然后前缀和优化一下即可 #include<iostream> #include<cstdio> using ...
- 1630/2023: [Usaco2005 Nov]Ant Counting 数蚂蚁
2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 85 Solved: 40[S ...
- BZOJ2023: [Usaco2005 Nov]Ant Counting 数蚂蚁
2023: [Usaco2005 Nov]Ant Counting 数蚂蚁 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 56 Solved: 16[S ...
- bzoj2023[Usaco2005 Nov]Ant Counting 数蚂蚁*&&bzoj1630[Usaco2007 Demo]Ant Counting*
bzoj2023[Usaco2005 Nov]Ant Counting 数蚂蚁&&bzoj1630[Usaco2007 Demo]Ant Counting 题意: t个族群,每个族群有 ...
- BZOJ 3384: [Usaco2004 Nov]Apple Catching 接苹果( dp )
dp dp( x , k ) = max( dp( x - 1 , k - 1 ) + *** , dp( x - 1 , k ) + *** ) *** = 0 or 1 ,根据情况 (BZOJ 1 ...
- bzoj 3384: [Usaco2004 Nov]Apple Catching 接苹果
双倍经验题... -->1750 dp!! 3384: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec Memory Limit: 12 ...
- bzoj 1914: [Usaco2010 OPen]Triangle Counting 数三角形 容斥
1914: [Usaco2010 OPen]Triangle Counting 数三角形 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 272 Sol ...
随机推荐
- Struts学习之流程汇总
struts2 架构图如下图所示: 依照上图,我们可以看出一个请求在struts的处理大概有如下步骤: 1.客户端初始化一个指向Servlet容器(例如Tomcat)的请求: 2.这个请求经过一系列的 ...
- 50句高级SQL语句
一个题目涉及到的50个Sql语句 --(下面表的结构以给出,自己在数据库中建立表.并且添加相应的数据,数据要全面些. 其中Student表中,SId为学生的ID) ------------------ ...
- 一周学会Mootools 1.4中文教程:(4)类型
Mootools的类型主要包含下边几部分:String:字符串;Number:数字;Array:数组;Object:对象;Json:;Cookie:. 这也是我们今天的讲述重点.每一种数据类型Mt都为 ...
- poj 1949 Chores 最长路
题目链接 求出最长路..... #include <iostream> #include <vector> #include <cstdio> #include & ...
- Linux发展历史大事编年表(截止2013年)
这篇文章主要介绍了Linux发展历史大事编年表(截止2013年),Linux现在已经无处不在,是一个伟大的开原项目,让我一起来看看23年来它的发展历程吧 我们周围到处都有Linux的身影,在家中. ...
- BZOJ 1096 [ZJOI2007]仓库建设(斜率优化DP)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1096 [题目大意] 有个斜坡,有n个仓库,每个仓库里面都有一些物品,物品数目为p,仓库 ...
- java的常见异常与错误总结
算术异常类:ArithmeticExecption 空指针异常类:NullPointerException 类型强制转换异常:ClassCastException 数组负下标异常:NegativeAr ...
- C/C++指针的指针(**p)和指针的引用(*&)使用案例分析
#include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <stdlib.h> ...
- java实现的Trie树数据结构
近期在学习的时候,常常看到使用Trie树数据结构来解决这个问题.比方" 有一个1G大小的一个文件.里面每一行是一个词.词的大小不超过16字节,内存大小限制是1M. 返回频数最高的100个词. ...
- 百度地图API 级别自动缩放
今天做一个基于百度地图API的小项目 查了很长时间apid都没有找到地图呈现出来的时候地图按坐标的多少自动缩放显示的等级比例,特此记录笔记!var points = [point1, point2,p ...