当前位置:网站首页>[Luogu] p2372 yyy2015c01 challenge perimeter (BFS)
[Luogu] p2372 yyy2015c01 challenge perimeter (BFS)
2022-04-22 18:56:00 【percation】

count (x,y) The perimeter of the connected block where the coordinates are located .
Perimeter : Judge whether there are four directions X, Is it across the border? , Statistical answer .
#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://yzsam.com/2022/04/202204221854198076.html
边栏推荐
- Micro star small aircraft performance monitoring settings
- 062 反序列化漏洞
- 2022年挖掘机司机(建筑特殊工种)复训题库及答案
- 爱可可AI前沿推介 (4.22)
- Simulation experiment of Arduino uno steering gear
- Global type in description file
- 校园跑腿平台如何搭建?
- 2019-11-19解决Go test执行单个测试文件提示未定义问题
- The 2022 language and intelligent technology competition was upgraded to launch four cutting-edge tasks of NLP
- 浅析局域网聊天软件的能力
猜你喜欢

JSP learning (VIII. JDBC and file upload processing project)

Model Inspector - software model static specification inspection tool

jsp学习(八.JDBC与文件上传处理的项目)

What does naas, a charging service provider, rely on to rise without building piles?

The Sandbox 与 Slipknot 以及 Knotfest 达成合作关系,共同打造 KNOTVERSE

错误 C4996 ‘fopen‘: This function or variable may be unsafe. Consider using fopen_s instead. To disabl

STC current interrupt list of all series

CDATA drivers for JIRA complete features and attributes

网络安全——Burp Suite抓包工具的使用

2022语言与智能技术竞赛再升级,推出NLP四大前沿任务
随机推荐
微服务调用组件Feign介绍
jsp学习(八.JDBC与文件上传处理的项目)
JSP learning (IX. filter, wildcard and cookie processing)
Type description file of module code
RHCE-ansible
The Sandbox 与 Apex Athletes 达成合作关系
It's fun to learn programming. Why don't you know where to start when you do a project alone?
2022年江西省安全员A证考试练习题及模拟考试
What does naas, a charging service provider, rely on to rise without building piles?
存储网络请求日志
数据分析师职业规划——数据分析师的职业焦虑与未来发展
Micro star small aircraft performance monitoring settings
Video knowledge points (16) - how to convert y4m files into YUV files?
2022語言與智能技術競賽再昇級,推出NLP四大前沿任務
jsp学习(九.Filter过滤器、通配符和Cookie处理)
Storage network request log
Stream demo
TypeScript中的命名空间使用
TabLayout + ViewPager2 + Fragment的简单应用
MacOS M1 使用 Homebrew 安装 Mysql