1249:Lake Counting

2024-01-31 10:52
文章标签 lake counting 1249

本文主要是介绍1249:Lake Counting,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

【题目描述】

题意:有一块N×M的土地,雨后积起了水,有水标记为‘W’,干燥为‘.’。八连通的积水被认为是连接在一起的。请求出院子里共有多少水洼?

【输入】

第一行为N,M(1≤N,M≤110)。

下面为N*M的土地示意图。

【输出】

一行,共有的水洼数。

【输入样例】

10 12
W........WW.
.WWW.....WWW
....WW...WW.
.........WW.
.........W..
..W......W..
.W.W.....WW.
W.W.W.....W.
.W.W......W.
..W.......W.

【输出样例】

3

【AC代码】

#include <bits/stdc++.h>
using namespace std;
int n,m;
char a[1001][1001];
int dx[9]= {-1,1,0,0,-1,1,-1,1};
int dy[9]= {0,0,-1,1,-1,1,1,-1};
struct node
{int x,y;
};
void bfs(int x1,int y1)
{queue<node> q;q.push({x1,y1});a[x1][y1]='0';while(!q.empty()){node xy;xy=q.front();q.pop();for(int i=0; i<8; i++){int xx=xy.x+dx[i],yy=xy.y+dy[i];if(xx>=1 &&xx<=n &&yy>=1 &&yy<=m &&a[xx][yy]=='W'){q.push({xx,yy});a[xx][yy]='.';}}}
}
int main()
{int cnt=0;cin>>n>>m;for(int i=1; i<=n; i++){for(int j=1; j<=m; j++){cin>>a[i][j];}}for(int i=1; i<=n; i++){for(int j=1; j<=m; j++){if(a[i][j]=='W'){bfs(i,j);cnt++;}}}cout<<cnt<<endl;return 0;
}

这篇关于1249:Lake Counting的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/663520

相关文章

POJ 2386 Lake Counting(DFS)

题目: http://poj.org/problem?id=2386 题解: 遍历一次,遇到w,一次DFS后,与此w连接的所有w都被替换成‘ . ’,直到遍历完图中不再存在w为止,总共进行DFS的次数就是答案了。 代码: #include<stdio.h>int N,M;char map[110][110];void dfs(int x,int y){map[x][y]='

重磅 | Delta Lake正式加入Linux基金会,重塑数据湖存储标准

大数据技术与架构 点击右侧关注,大数据开发领域最强公众号! 暴走大数据 点击右侧关注,暴走大数据! 作者:wwwzw By 暴走大数据 场景描述:2019年10月16日,在荷兰阿姆斯特丹举行的 Spark+AI 欧洲峰会上,DataBricks 和 Linux

[LeetCode] 338. Counting Bits

题:https://leetcode.com/problems/counting-bits/description/ 题目 Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary repres

《Zero-Shot Object Counting》CVPR2023

摘要 论文提出了一种新的计数设置,称为零样本对象计数(Zero-Shot Object Counting, ZSC),旨在测试时对任意类别的对象实例进行计数,而只需在测试时提供类别名称。现有的类无关计数方法需要人类标注的示例作为输入,这在许多实际应用中是不切实际的。ZSC方法不依赖于人类标注者,可以自动操作。研究者们提出了一种方法,可以从类别名称开始,准确识别出最佳的图像块(patches),用

Swift 3.0 学习 -- 计算字符数量 (Counting Characters)

在swift2.0的时候,可以通过调用全局countElements函数,并将字符串作为参数进行传递,可以获取该字符串的字符数量。如下: let unusualMenagerie = "Koala, Snail, Penguin, Dromedary"print("unusualMenagerie has \(countElements(unusualMenagerie)) charact

leetcode338 Counting Bits Java

Description Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1’s in their binary representation and return them as an array. Example: Fo

UVA 11401 Triangle Counting

中文详解请访问我的博客:http://xiaoshig.sinaapp.com/?p=128 You are given n rods of length 1, 2…, n. You have to pick any 3 of them & build a triangle. How many distinct triangles can you make? Note that, two

sdut2610--Boring Counting(二分+划分树)

Boring Counting Time Limit: 3000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述     In this problem you are given a number sequence P consisting of N integer and Pi is the ith element in the

论文笔记 A Large Contextual Dataset for Classification,Detection and Counting of Cars with Deep Learning

ECCV 2016的文章,首先建立了一个从上到下照的车辆影像数据集(即鸟瞰视角),并提出ResCeption神经网络进行训练,进一步建立residual learning with Inception-style layers,进行车辆数目的计算。该方法为车辆数目的计算的一种新方式:通过定位和密度估计方法。对于新的场景或新的目标计数也同样适用。 文章主要关注3个任务点:(1)两类的分类问题(2)

数据湖之Delta Lake

Delta Lake:数据湖存储层概述 Delta Lake 是一种开源的存储层技术,构建在 Apache Spark 的基础之上,旨在解决传统数据湖的可靠性、性能和数据一致性问题。它通过引入 ACID 事务、数据版本控制、时间旅行和统一的批处理与流处理等特性,显著提升了数据湖的可用性和数据管理能力。Delta Lake 由 Databricks 推出,现已成为现代数据湖架构的核心组件。