Lake Counting S

2024-03-31 21:48
文章标签 lake counting

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

Lake Counting S

洛谷P1596

在这里插入图片描述
在这里插入图片描述
一道典型深搜题 把字符存成数字就变成了种子填充的题
思路:

  1. 设置变量和flag
  2. 输入 将字符变成数字
  3. 用深搜判断
  4. 输出结果
#include <iostream>
using namespace std;int g[100][100];
bool flag[100][100];
int n,m,ans=0;
char c=0;void dfs (int x,int y)
{if (x>=n || y>=m || x<0 || y<0 || flag[x][y]==1)return ;flag[x][y]=1;if (g[x][y]==1){dfs(x+1,y);dfs(x-1,y);dfs(x,y+1);dfs(x,y-1);dfs(x-1,y-1);dfs(x-1,y+1);dfs(x+1,y+1);dfs(x+1,y-1);}elsereturn ;}int main ()
{cin >> n >> m;for (int i=0;i<n;i++){for (int j=0;j<m;j++){cin >> c;if (c=='W')g[i][j]=1;elseg[i][j]=0;}}for (int i=0;i<n;i++){for (int j=0;j<m;j++){if (flag[i][j]==0 && g[i][j]==1){dfs(i,j);ans++;}}}cout << ans << endl;return 0;
}

此题解已AC,也欢迎指出更多优化方法~

❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀❀

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



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

相关文章

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 推出,现已成为现代数据湖架构的核心组件。