洛谷P1596 [USACO10OCT] Lake Counting S

题解:洛谷 P1596 [USACO10OCT] Lake Counting S 等知名刷题平台精心挑选而来,并结合各平台提供的算法标签和难度等级进行了系统分类。题目涵盖了从基础到进阶的多种算法和数据结构,旨在为不同阶段的编程学习者提供一条清晰、平稳的学习提升路径。农夫约翰想要弄清楚他的田地里形成了多少个水塘。一个水塘是由连通的水方格组成的,其中一个方格被认为与它的八个邻居相邻。给定农夫约翰田地的示意图,确定他有多少个水塘。由于最近的降雨,水在农夫约翰的田地里积聚了。个字符,表示农夫约翰田地的一行。行:农夫约翰田地中的水塘数量。#普及-# #BFS-二维#每个方格中要么是水( 阅读详情

这种普通走迷宫的题,还是最好用bfs,毕竟复杂度是比dfs低的。但我这用dfs讲解。
具体思路就不做详解,看代码注释。

Code

#include <bits/stdc++.h>
using namespace std;
int n, m;
char a[105][105];
int dx[8] = {0,1,-1,0,-1,1,-1,1};//搜索的八个方向常量,x
int dy[8] = {1,0,0,-1,-1,1,1,-1};//同上,y
void dfs(int x,int y){
	for(int i=0;i<8;i++){//枚举八个方向
		int tx = x + dx[i];//记录变化的x坐标
		int ty = y + dy[i];//同上,y坐标
		if(a[tx][ty] == 'W' && tx >= 1 && tx <= n && ty >= 1 && ty <= m){//判断是否是水洼以及有没有越界
			a[tx][ty] = '.';//将其变成'.',防止重复
			dfs(tx,ty);//从这个地方继续dfs。
		}
	}
}
int main(){
	cin >> n >> m;//输入地图长宽
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin >> a[i][j];//输入地图
		}
	}
	int num=0;//最终答案初始化
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(a[i][j] == 'W'){//寻找水洼
				num ++;//将水洼个数加1
				a[i][j] = '.';//为防止dfs重复计算将其变成'.'
				dfs(i,j);//开始dfs
			}
		}
	}
	cout << num;//输出答案
	return 0;
}
MATLAB/simulink电力系统之变压器仿真+变压器饱和仿真+空载变压器电流畸变原因及仿真+空载合闸励磁涌流仿真+simulink免费仿真资源 单相变压器空载运行时,原边电流主要用来产生主磁场,而电路损耗和铁芯损耗很小,因此即使外加电压很大,空载电流仍然很小。如果想观察某个相对磁导率下电感系数的数值,可以在程序中增加这样的语句,比如,在程序中end语句之后,加上L(100),运行程序后就可以得到相对磁导率为 100时的电感系数值。在交流铁芯线圈中,当交变磁通按照正弦规律变化时,受到磁路饱和的影响,线圈中的电流会发生畸变,并成为尖顶波,这就是所谓的交流磁路电流畸变。需要指出,铁芯内的主磁通Ф可以通过空载时的副边电压从来测量,两者之间的数学关系,即。 阅读详情

相关推荐

LoRa项目实战:手把手教你为ESP32选配和焊接天线(从PCB到信号测试)

本文详细介绍了为ESP32选配和焊接LoRa天线的全流程,包括天线选型、PCB布局设计、焊接工艺及信号测试。重点解析了PCB板载天线、导线天线和陶瓷贴片天线的适用场景与性能特点,并提供专业的焊接技巧和信号测试方案,帮助开发者优化LoRa模块的无线通信性能。

weixin_30470643的博客 393

Luogu P1596 [USACO10OCT]湖计数Lake Counting

题目描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square ...

629

快速了解Spyder

一 面板介绍菜单栏:放置所有功能工具栏:放置快捷菜单,可以通过菜单栏中的View的Toolbars的复选框来勾选工作区:写代码的地方属性页的标题栏:可以显示当前代码的名字和位置查看栏:查看文件、调试时的对象及变量输出栏:查看程序的输出信息,也可以作为shell终端来输入Python语句状态栏:用来显示当前文件权限、编码,光标指向位置和系统内存二 注释功能注释功能为编写代码很常用功能,下面介绍Spy...

实践求真知 1万+

洛谷 P1596 [USACO10OCT] Lake Counting S 刷题笔记

/有可能当前位置的水与前面搜索的水联通被记为了陆地 所以要先判断一下。//将四条边界标记为陆地。//确定当前是一块未被搜索过的 新 水。//如果下个位置为水且没有越界。观察 对于水来说 其八个方向相邻都属于同一个联通块。我们可以存水的位置 搜索每个水可以到达的所有位置。将搜过的位置标记为陆地避免重复搜索。一道判断有多少个联通块的问题。

2301_78763076的博客 1139

大漠多线程增强版:解决窗口消失、坐标错乱与识别卡死

多线程环境下窗口自动化面临的核心挑战,本质是GDI资源非线程安全、HWND生命周期失控及图像引擎状态污染三大底层问题。Windows GUI编程中,跨线程共享hDC、缓存失效的窗口句柄、OpenCV静态Mat等设计缺陷,导致FindPic失败、GetCursorPos异常、坐标跳变等典型故障。本方案通过线程局部存储(TLS)重构资源生命周期、WinEventHook+心跳探测构建实时窗口状态链、ABI对齐的多语言内存契约,实现稳定低延迟的并发UI识别与控制。适用于游戏多开监控、电商RPA、后台UI状态采集等

weixin_30561177的博客 477

20 硬件工程师笔面试高频考点真题解析——寄存器

摘要: 寄存器是由多个边沿触发的D触发器组成的多位存储单元,用于同步时序电路中的数据暂存、隔离毛刺、跨时钟域同步等。选型需考虑位宽、触发方式(边沿/电平)、异步控制、电气参数等。核心时序参数包括建立时间(Tsu)、保持时间(Thold)和时钟输出延迟(Tco)。寄存器广泛应用于时序逻辑、流水线分割、毛刺消除、跨时钟域同步及计数分频等场景。同步复位依赖时钟边沿,时序易收敛但需时钟支持;异步复位独立于时钟,上电可靠但需注意亚稳态风险。

XU157303764的博客 1342

洛谷—P1596 [USACO10OCT] Lake Counting S(DFS)

【代码】P1596 [USACO10OCT] Lake Counting S(DFS)

2301_79724394的博客 348

生成EtherCAT从站XML图片信息方法

详细介绍了EtherCAT从站XML文件中图片元素的生成方法。

kevin1499的博客 2129

洛谷.P1596 [USACO10OCT] Lake Counting S

洛谷,菜菜奋斗小记,C++

2402_88149600的博客 253

nRF52832——大量数据传输时导致蓝牙断开连接,且无法被搜索到的解决方案(广播参数的设置、程序设计方法)

有时蓝牙通信单次发送数据量较大,且连续发送多次的时候,你会发现蓝牙就会出现异常,可能运行30min,40min,或者1h后,蓝牙就不能传输数据了,且无法被搜索到,用主机扫描蓝牙时可能会提示类似这样的DEBUG信息:bta_gattc_mark_bg_conn unable to find the bg connection mask for bd_addr=xx:xx:xx:xx:xx:xx。

数字世界 万物互联 2006

使用MATLAB进行灰色预测 GM(1,1)

使用MATLAB进行灰色预测 GM(1,1)

Hou_____的博客 998

洛谷 P1596 [USACO10OCT] Lake Counting S 题解 BFS

广度优先搜索 BFS 洛谷题解 C++代码 附详细注释

一只摸鱼的bbc 860

Python 爬虫实战:共享单车数据采集全流程与市场洞察深度剖析

本文介绍了如何利用Python爬虫技术获取和分析共享单车运营数据。文章从项目背景出发,详细阐述了系统架构设计,包括数据抓取、清洗存储、分析和可视化模块。通过Scrapy、BeautifulSoup等工具实现数据采集,使用Pandas进行数据清洗,并借助Matplotlib进行可视化分析。实战部分展示了爬虫代码示例和城市分布、使用频率等分析案例。最终指出数据驱动分析有助于了解行业现状和市场趋势,未来可结合机器学习等方法进行深入洞察。该技术方案为共享单车行业研究提供了有效的数据支持。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 2232

洛谷 P1596 [USACO10OCT] Lake Counting S

在输入数组后,遍历,如果遇到'W'就进行搜索,为了避免重复搜索,一旦查找到'W',就将其设置为'.',并进行下一次搜索,在8个方向都搜索完后,退出搜索,并将ans+1。一个网格与其周围的八个网格相连,而一组相连的网格视为一个水坑。给出约翰田地的示意图,确定当中有多少水坑。由于近期的降雨,雨水汇集在农民约翰的田地不同的地方。我们用一个 N×M(1≤N≤100,1≤M≤100) 的网格图表示。输入第 11 行:两个空格隔开的整数:N 和 M。,它们表示网格图中的一排。输出一行,表示水坑的数量。

leo_0808c的博客 960

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

洛谷-P1596 [USACO10OCT] Lake Counting S

【代码】洛谷-P1596 [USACO10OCT] Lake Counting S。

m0_74105654的博客 711

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

洛谷P1596 [USACO10OCT] Lake Counting S,题解

P1596 [USACO10OCT] Lake Counting S

chehangyuchy的博客 415

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

洛谷 P1596 [USACO10OCT]Lake Counting S(dfs,搜就完事儿了

洛谷 P1596 题目大意: 找一块儿地中水池的个数。 基本思路: 找到一个水池块时,将所有与他相连的水池块全部标记。 且不越过旱地块儿。 减枝操作:如果这个水池块儿搜过,那么就不用再搜了。 什么时候更新最大值? 当主函数中的循环,搜到新的水池块儿时, 也是第一次搜到这个点,ans++。 预处理: for(i=0;i<n;i++){ for(j=0;j<m;j++) { cin>>c; if(c=='W') k[i][

yxrzibinanhai的博客 467

洛谷:P1596 [USACO10OCT] Lake Counting S Java题解

题目要求我们计算一个N×M的田地中有多少个水塘。水塘由相邻的’W’(水)组成,相邻包括八个方向(上下左右和四个对角线)。我们需要遍历整个田地,找到所有连通的水区域。该解法高效且易于理解,能够正确处理题目给定的最大数据规模(100×100的田地)。:O(N×M),其中N和M分别是田地的行数和列数。每个格子最多被访问一次。:O(N×M),用于存储标记数组和输入数据。

Java爱好者,热爱分享,信仰开源! 392

洛谷 P1596 [USACO10OCT]Lake Counting S (尚贤)

【题目】:https://www.luogu.com.cn/problem/P1596 #include <cstdio> struct node{ int x, y; node(){ } node(const int &xx, const int &yy) { x = xx, y = yy; } } a[10005]; char map[105][10...

广东省清远市博爱学校—尚贤的博客 289

[洛谷]P1596 [USACO10OCT]Lake Counting S

一道DFS判断连通块的题目。

m0_74969835的博客 234

洛谷 P1596 [USACO10OCT] Lake Counting S-普及-

农夫约翰想要弄清楚他的田地里形成了多少个水塘。一个水塘是由连通的水方格组成的,其中一个方格被认为与它的八个邻居相邻。给定农夫约翰田地的示意图,确定他有多少个水塘。思路:用 dfs 搜索 W 以及周围四个方向的 W,独立搜索(即不是从其它W递归搜索)次数就是水塘水量。输出详情:共有三个水塘:一个在左上角,一个在左下角,还有一个沿着右侧。由于最近的降雨,水在农夫约翰的田地里积聚了。个字符,表示农夫约翰田地的一行。(由 ChatGPT 4o 翻译)行:农夫约翰田地中的水塘数量。每个方格中要么是水(

weixin_37253733的博客 604

洛谷 P1596 [USACO10OCT]Lake Counting S

由于近期的降雨,雨水汇集在农民约翰的田地不同的地方。我们用一个 N\times M(1\leq N\leq 100, 1\leq M\leq 100)N×M(1≤N≤100,1≤M≤100) 的网格图表示。一个网格与其周围的八个网格相连,而一组相连的网格视为一个水坑。给出约翰田地的示意图,确定当中有多少水坑。显而易见的,这是一道很基础的DFS题目,当然也可以用BFS,不过我觉得DFS更顺溜一点罢了。第 22 行到第 N+1N+1 行:每行 MM 个字符,每个字符是。,它们表示网格图中的一排。

弹炒饭的博客 449

洛谷P1596 [USACO10OCT]Lake Counting S

题目描述 Due to recent rains, water has pooled in various places in Farmer John’s field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water (‘W’) or dry land (’.’). Farmer John wou

ZHHABBBBB的博客 154
上一篇: 洛谷B3621枚举元组
下一篇: 洛谷P1825 [USACO11OPEN] Corn Maze S
White__Night__
博客等级 码龄3年 230粉丝 31原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值