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 ...
随机推荐
- Linux远程自动输入密码抓取远程资源
#!/usr/bin/expect -fset timeout 3000set sys_date [lindex $argv 0] #要抓取的文件日期spawn scp /data3/xiaorui/ ...
- iOS中点击背景收键盘
这一次给大家带来的是ios中点击背景如何收键盘(感觉不错给个赞
- Mac之vim普通命令使用
Mac之vim普通命令使用 标签: vim命令 高级一些的编辑器,都会包含宏功能,vim当然不能缺少了,在vim中使用宏是非常方便的: :qx 开始记录宏,并将结果存入寄存器x q 退出记录模式 @x ...
- hadoop之hdfs学习
简介 HDFS(Hadoop Distributed File System )Hadoop分布式文件系统.是根据google发表的论文翻版的.论文为GFS(Google File System)Go ...
- mysql不区分大小写解决
今天遇到一个情况,前台验证用户昵称的时候发现无论输入Fred fred亦或是FrEd 都会显示昵称存在(这并不是我所期望的结果) debug发现并不是程序问题 hibernate也只是吧hql装成my ...
- qt学习:信号,槽
[C.GUI.Qt.4编程(第二版)](加)布兰切特,(英)萨默菲尔德.扫描版[学习库www.xuexi111.com].pdf 信号和槽是Qt编程的基础,它可以让各种对象联系在一起. 1. 使用co ...
- oracle查询字符集语句
(1)查看字符集(三条都是等价的) 复制代码 代码如下: select * from v$nls_parameters where parameter='NLS_CHARACTERSET'sel ...
- .NET(C#):XmlArrayItem特性和XmlElement特性在序列化数组的差别
原文http://www.cnblogs.com/mgen/archive/2011/12/04/2276238.html 比如这样一个类,我们用XmlArrayItem特性标明数组内出现的元素类型: ...
- Jsoup代码解读之一-概述
Jsoup代码解读之一-概述 今天看到一个用python写的抽取正文的东东,美滋滋的用Java实现了一番,放到了webmagic里,然后发现Jsoup里已经有了…觉得自己各种不靠谱啊!算了,静下心来学 ...
- js秒数转换时分秒方法
今天写一个东西的时候 发现给出的是秒数.实在找不到直接的工具去转换. 就去网上找了个转换方法(有现成的就不写了,以后再简化下代码). function formatSeconds(value) { v ...