codevs3410 别墅房间
题目描述 Description
小浣熊松松到他的朋友家别墅去玩,发现他朋友的家非常大,而且布局很奇怪。具体来说,朋友家的别墅可以被看做一个N*M的矩形,有墙壁的地方被标记为’#’,其他地方被标记为’.’。两个格子(a,b)和(c,d)被当做在同一个房间内,当且仅当|a-c|+|b-d|=1。现在松松想知道,有多少个房间。
第一行包含两个整数,N和M。
接下来N行描述别墅的情况,只包含’*’和’.’。
输出仅一行,为房间数。
3 3
.#.
#.#
.#.
5
对于90%的数据,1<=N,M<=1000;
对于100%的数据,1<=N,M<=2000。
思路:
bfs求连通块
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string> using namespace std;
const int maxn = ;
int j[maxn][maxn],room[maxn][maxn];
long long int total = ,m,n;
struct pos{
int x;
int y;
};
pos q[];
pos dir[]; int bfs(int y,int x){
int h = ,t = ;
q[].y = y;
q[].x = x;
int tx,ty;
while(h <= t){ int r3 = ;
for(r3 = ;r3 < ;r3++){
x = q[h].x;
y = q[h].y;
tx = dir[r3].x;
ty = dir[r3].y;
if(y + ty >= && y + ty < n && x + tx >= && x + tx < m && room[y + ty][x + tx] && j[y + ty][x + tx]){
t++;
q[t].y = y + ty;
q[t].x = x + tx;
j[y + ty][x + tx] = ;
total--;
}
}
h++ ;
}
} int main(){
cin>>n>>m;
dir[].x = -;dir[].y = ;
dir[].x = +;dir[].y = ;
dir[].x = ;dir[].y = -;
dir[].x = ;dir[].y = +;
char cmd;
int r1 = ,r2 = ,temp = -;
for(r1 = ;r1 < n;r1++){
for(r2 = ;r2 < m;r2++){
cin>>cmd;
if(cmd == '.') {
j[r1][r2] = ;
room[r1][r2] = ;
total++;
}else if(cmd == '#'){
j[r1][r2] = ;
room[r1][r2] = ;
}
}
}
r1 = r2 =;
for(r1 = ;r1 < n;r1++){
for(r2 = ;r2 < m;r2++){
if(room[r1][r2] && j[r1][r2]){
j[r1][r2] = ;
bfs(r1,r2);
} }
}
cout<<total;
return ;
}
codevs3410 别墅房间的更多相关文章
- 别墅房间 CodeVS原创
时间限制: 1 s 空间限制: 64000 KB 题目等级 : 青铜 Bronze 题目描述 Description 小浣熊松松到他的朋友家别墅去玩,发现他朋友的家非常大,而且布局很奇怪.具体来说,朋 ...
- codevs 搜索题汇总(青铜+白银级)
1792 分解质因数 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 青铜 Bronze 题目描述 Description 编写一个把整数N分解为质因数乘积的程序. 输入描 ...
- ACM 房间安排
房间安排 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间, ...
- 房间安排-nyoj168
描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间,在中国上海市举行.本次世博会也是由中国举办的首届世界博览会.上海世博会以“城市,让生活 ...
- 房间声学原理与Schroeder混响算法实现
一.混响时间的计算与预测 所谓混响就是声音的直达声与反射声很紧凑的重合在一起时人耳所听到的声音,这个效果在语音的后期处理时特别有用.能产生混响最常见的场景就是房间内,尤其是空旷的房间中. 混响有直达声 ...
- nyoj 168 房间安排(区间覆盖)
房间安排 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 2010年上海世界博览会(Expo2010),是第41届世界博览会.于2010年5月1日至10月31日期间, ...
- bzoj 4031: [HEOI2015]小Z的房间 轮廓线dp
4031: [HEOI2015]小Z的房间 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 98 Solved: 29[Submit][Status] ...
- Delphi直接让QT进入指定房间
WinExec('./QT/QT.exe qt://join/?roomid=3955&subroomid=287307288&ext=gid:536023504;et:1001', ...
- CodeForces 554B(扫房间)
CodeForces 554B Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- Parameterized testing with any Python test framework
1. 在进行单元测试时,很多时候需要进行参数化 尝试过使用 from nose_parameterized import parameterized 但在使用过程中会报错,后来将上面的内容改为了下面的 ...
- 生成 Guid
//生成Guid function getGuidGenerator() { var S4 = function () { return (((1 + Mat ...
- [POI2013]POL-Polarization
题目描述 Everyone knew it would only be a matter of time. So what? Faced for years on, a peril becomes t ...
- Codefoces 828C
C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 二分图最大匹配(匈牙利算法) POJ 3020 Antenna Placement
题目传送门 /* 题意:*的点占据后能顺带占据四个方向的一个*,问最少要占据多少个 匈牙利算法:按坐标奇偶性把*分为两个集合,那么除了匹配的其中一方是顺带占据外,其他都要占据 */ #include ...
- kafka启动时出现FATAL Fatal error during KafkaServer startup. Prepare to shutdown (kafka.server.KafkaServer) java.io.IOException: Permission denied错误解决办法(图文详解)
首先,说明,我kafk的server.properties是 kafka的server.properties配置文件参考示范(图文详解)(多种方式) 问题详情 然后,我启动时,出现如下 [hadoop ...
- 第八届蓝桥杯省赛C/C++ A组第4题 方格分割
参考了http://blog.csdn.net/y1196645376/article/details/69718192,这个大哥的思路很巧妙. 思路: dfs. 实现: #include <i ...
- bootstrap3无间距栅格/grid no-gutter
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- git 分支处理
git 创建常用(多)分支(如:Master 主分支.Develop 分.Feature 功能分支.Release 预发布分支.Hotfix(或者Fixbug) 分支)步骤1.mkdir 项目名 ...
- nginx反向代理与负载均衡讲解
Nginx的代理功能与负载均衡功能是最常被用到的,关于nginx的基本语法常识与配置已在上篇文章中有说明,这篇就开门见山,先描述一些关于代理功能的配置,再说明负载均衡详细. Nginx代理服务的配置说 ...