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 ...
 
随机推荐
- iOS内购的订单对应和补单
			
内购的关键类: 1.SKPayment(SKMutablePayment可将自己的参数一对一与苹果产生的payment对应起来) 2.TransactionObserver:交易状态更新时执行此方法, ...
 - VC6神迹外挂的DIY
			
2014年09月05日 ⁄ 综合 ⁄ 共 8724字 ⁄ 字号 小 中 大 ⁄ 评论关闭 (一)外挂一般都能在游戏的界面中按一个热键(比如F12,HOME等),就可以呼出外挂的窗口,然后在里面进行外挂 ...
 - javascript块级作用域
			
在c/java中,拥有块级作用域的概念,大括号内就是一个块级作用域,在块级作用域内声明的变量,块以外不可见. C语音的块级作用域示例如下: ,two = ; if(one < two){ ; t ...
 - bzoj 1088: [SCOI2005]扫雷Mine
			
题目链接 1088: [SCOI2005]扫雷Mine Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2525 Solved: 1495[Submi ...
 - call和apply方法的理解
			
第一种:直接先来个粟子吧... ; } var child = {}; console.log(child); //Object() 对象 Parent.call(child); console. ...
 - Nancy之实现API
			
Nancy之实现API的功能 0x01.前言 现阶段,用来实现API的可能大部分用的是ASP.NET Web API或者是ASP.NET MVC,毕竟是微软官方出产的,用的人也多. 但是呢,Nancy ...
 - 走进Groovy (二)
			
承接上一篇,配置好环境后,开始正式学习语法.我假设看此文的同学至少会一定的JAVA语法,因此一些太过基础的就不记录了,基本上,大家看看示例就明白了. Groovy的卖点之一,就是全兼容JAVA的语法, ...
 - iphone 4 safrai fixed
			
<script type="text/javascript"> if(navigator.userAgent.indexOf("Safari")&g ...
 - 实现将VirtualBox 虚拟机转换为KVM虚拟机的步骤
			
原来在桌面上一直使用virtualbox虚拟机管理程序(VMM)构建虚拟机安装不同的操作系统,现在 研究linux下的KVM,能否将已经建立的virtualBox虚拟客户机(guest)转换为KVM虚 ...
 - rsyslog 基本组成
			
Facility 定义日志消息的来源,以方便对日志进行分类,facility 有以下几种: --kern 内核消息 --user 用户级消息 --mail 邮件系统消息 --daemon 系统服务消息 ...