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 ...
随机推荐
- HelloWorld——Cocos2d-x学习历程(二)
HelloWorld分析: 1."resource"文件夹 该文件夹主要用于存放游戏中需要的图片.音频和配置等资源文件. 2."include"和"s ...
- apache hide index.php
<Directory "D:/usr/local/www"> AllowOverride all Options +FollowSymLinks +SymL ...
- mahout算法源码分析之Collaborative Filtering with ALS-WR 并行思路
Mahout版本:0.7,hadoop版本:1.0.4,jdk:1.7.0_25 64bit. mahout算法源码分析之Collaborative Filtering with ALS-WR 这个算 ...
- sublime模式下开启vim并修改esc
首先我用的是sublime text2 sublime下开启vim模式: 在Preference -> Setting-User里面加上 "ignored_packages" ...
- POJ 2110 Mountain Walking 二分+bfs
传送门 昨天看到这个题还以为是个脑残的dp, 然而脑残的是我. 题目意思就是从左上角走到右下角, 设x为路径上的最大值-最小值, 求x的最小值. 二分x, 对于每一个x, 枚举下界lower, low ...
- poj 1949 Chores 最长路
题目链接 求出最长路..... #include <iostream> #include <vector> #include <cstdio> #include & ...
- IOS 特定于设备的开发:监测Retina支持
近年来,Apple在其旗舰设备上引入了Retina显示屏.根据Apple的说法,他的像素密度非常高,足以使人眼无法区分单独的像素. UIScreen类提供了一种容易的方式,用于监查当前设备是否提供了内 ...
- Windows 安装 psutil
第一步:下载pustil 网址:https://pipy.python.org (http://yunpan.cn/cJg8aQpYwqfzh (提取码:7fa7)) 第二步:安装这个就没有什么好说 ...
- flume 日志采集工具
Flume是Cloudera提供的一个高可用的,高可靠的,分布式的海量日志采集.聚合和传输的系统,Flume支持在日志系统中定制各类数据发送方,用于收集数据:同时,Flume提供对数据进行简单处理,并 ...
- Android使用XML全攻略(1)
Android使用XML全攻略(1) Android 是针对移动设备的一种新兴的开源操作系统和 SDK.借助它,您可以创建功能强大的移动应用程序.当您的应用程序可以访问 Web 服务时,其吸引力 ...