当前位置:网站首页>【洛谷】P2372 yyy2015c01挑战算周长(BFS)
【洛谷】P2372 yyy2015c01挑战算周长(BFS)
2022-04-22 18:55:00 【percation】

算(x,y)坐标所在位置的连通块的周长。
周长:判断四个方向有无X,是否越界,统计答案。
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef pair<int,int> pii;
const int N = 2e2 + 10;
char g[N][N];
int n,m;
int x,y;
int ans;
pii q[N*N];
bool st[N][N];
bool vis[N][N];
void bfs(int sx, int sy){
int hh = 0, tt = 0;
q[0] = {
sx,sy};
st[sx][sy] = true;
while(hh <= tt){
pii t = q[hh++];
for(int i = t.x - 1; i <= t.x + 1; i++){
for(int j = t.y - 1; j <= t.y + 1; j++){
if(i == t.x && j == t.y) continue;
if((i < 1 || i > n || j < 1 || j > m )){
if(((i== t.x - 1 && j == t.y) || (i== t.x + 1 && j == t.y) || (i== t.x && j == t.y + 1) || (i== t.x && j == t.y - 1))){
ans++;
}
continue;
}
if(i < 1 || i > n || j < 1 || j > m) continue;
if(!st[i][j] && g[i][j] == 'X'){
st[i][j] = true;
q[++tt] ={
i,j};
continue;
}
if(((i== t.x - 1 && j == t.y) || (i== t.x + 1 && j == t.y) || (i== t.x && j == t.y + 1) || (i== t.x && j == t.y - 1))&& g[i][j] == '.' ){
ans++;
}
}
}
}
}
int main(){
cin >> n >> m >> x >> y;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
char c;
cin >> c;
g[i][j] = c;
}
}
bfs(x,y);
cout << ans << endl;
return 0;
}
版权声明
本文为[percation]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_45866781/article/details/124348432
边栏推荐
- server端密码加密
- 2020-12-15 rocksdb研究
- 单片机红外模块知识分享,理论是日后实战的基础
- nodejs文件操作
- [proteus simulation] 51 single chip microcomputer 8-way actuator inching ± 90 ° inching control
- The sandbox has entered into a cooperative relationship with apex athetes
- MacOS M1 使用 Homebrew 安装 Mysql
- [TCP] TCP three handshakes and four waves
- Classes and objects - 5
- On the ability of LAN chat software
猜你喜欢

Take you to understand the principle of highly flexible spark architecture

CDATA drivers for JIRA complete features and attributes

聊聊我这些年错过的一些机遇

RHCE-ansible

HMS Core Discovery第14期回顾长文|纵享丝滑剪辑,释放视频创作力

nodejs如何预防xss攻击

如何设计 API 接口,实现统一格式返回

The sandbox has entered into a cooperative relationship with apex athetes

On the ability of LAN chat software

C language precompiling (preprocessing) define
随机推荐
Model Inspector — 软件模型静态规范检查工具
Introduction notes to PHP zero Foundation (12): array
STC目前所有系列的中断列表
The sandbox has entered into a cooperative relationship with apex athetes
描述文件中的全局类型
使用RectclerView的一些问题记录
【Proteus仿真】51单片机8路舵机点动±90°点动控制
2020-09-08 去除js代码的注释
Namespace usage in typescript
server端密码加密
CVPR2022 | 跨模态检索的协同双流视觉语言预训练模型
Simple implementation of linear regression
Talk about some opportunities I've missed over the years
为什么不能直接在 useEffect 中使用 async
CData Drivers for Jira完整的特征和属性
华为云媒体査勇:华为云在视频AI转码领域的技术实践
AWSL!这波回忆杀真的爱了!
Simulation experiment of Arduino uno steering gear
C#与 Halcon 联合编程
微星小飞机 性能监控设置