当前位置:网站首页>Uva572 oil deposits problem solution
Uva572 oil deposits problem solution
2022-07-24 08:03:00 【bj_ hacker】
UVA572 Oil field Oil Deposits Answer key
subject
https://www.luogu.com.cn/problem/UVA572
Code implementation
#include<bits/stdc++.h>
using namespace std;
const int maxn=100+10;
const int dx[]={
-1,1, 0,0,-1, 1,-1,1};
const int dy[]={
0,0,-1,1,-1,-1, 1,1};
int n,m,ans;
int a[maxn][maxn],que[maxn*maxn][2];
bool vis[maxn][maxn];
inline bool inbound(int x,int y){
return x>=1&&x<=n&&y>=1&&y<=m;}
int main(){
//freopen("a.in","r",stdin);
//freopen("a.out","w",stdout);
while(1){
memset(vis,false,sizeof(vis));
ans=0;
scanf("%d%d",&n,&m);
if(n==0)break;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
char op;
scanf(" %c",&op);
if(op=='*')vis[i][j]=true;
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(!vis[i][j]){
ans++;
int head=0,tail=0;
vis[i][j]=true;
que[tail][0]=i;
que[tail++][1]=j;
while(head<tail){
int x=que[head][0],y=que[head++][1];
for(int k=0;k<8;k++){
int nx=x+dx[k],ny=y+dy[k];
if(inbound(nx,ny)&&!vis[nx][ny]){
vis[nx][ny]=true;
que[tail][0]=nx;
que[tail++][1]=ny;
}
}
}
}
}
}
printf("%d\n",ans);
}
return 0;
}
边栏推荐
- Kotlin coroutine (II): scope and cancellation
- Jetson AgX Orin source change
- 2021-06-03 database query - sorting
- Solve the problem that Anaconda navigator cannot be opened
- [matlab] (IV) application of MATLAB in linear algebra
- 【golang从入门到实践】学生成绩管理系统
- The growth path of software testing
- (dkby) DFL learning notes
- mysql update 使用case when根据某一字段的值,更新另一字段的值
- Introduction of some functions or methods in DGL Library
猜你喜欢

Digital twin demonstration project -- Talking about simple pendulum (3) solid model exploration

Movie recommendation system

Devops essay

When does MySQL use table locks and row locks?

Debug No3 multi texture overlay

*Code understanding * common function parsing in pytoch

*Yolo5 learning * data experiment based on yolo5 face combined with attention model CBAM

Function analysis of e-commerce website development and construction
![[matlab] (IV) application of MATLAB in linear algebra](/img/c8/97fddb4105008990173247b1b4a155.png)
[matlab] (IV) application of MATLAB in linear algebra

避坑,职场远离PUA,PUA常见的套路与话术你得了解一下!
随机推荐
DevOps随笔
EZDML逆向工程导入数据库分析实操教程
Eight part essay on software testing
Kotlin coroutine (II): scope and cancellation
Case practice - panoramic image mosaic: feature matching method
UVA572油田 Oil Deposits题解
P1135 奇怪的电梯题解
Generative model and discriminant model
Full revolutionary Siamese networks for object tracking translation
RBM contrast divergence
DGL库中一些函数或者方法的介绍
Avoid pitfalls and stay away from PUA in the workplace. You need to know the common routines and scripts of PUA!
45. Jumping game II
Debug No3 multi texture overlay
Kubernetes:(一)基本概念
*Yolo5 learning * data experiment based on yolo5 face combined with attention model CBAM
What is NFT? An article to understand the concept of NFT
Semantic slam: Probabilistic Data Association for semantic slam
2021-06-03 database query - sorting
Natural language processing Jieba