1252. 奇数值单元格的数目

FPGA实战:AXI BRAM Controller写时序避坑指南(附Vivado配置步骤) 本文深入探讨了FPGA开发中AXI BRAM Controller的写时序实战要点与常见陷阱。文章聚焦于写地址与写数据通道的握手机制,详细解析了AWREADY、WVALID等关键信号的处理,并提供了Vivado中流水线深度、ECC等关键参数的配置步骤与优化建议,旨在帮助开发者有效规避时序问题,提升系统性能。 阅读详情

给你一个 n 行 m 列的矩阵,最开始的时候,每个单元格中的值都是 0。

另有一个索引数组 indices,indices[i] = [ri, ci] 中的 ri 和 ci 分别表示指定的行和列(从 0 开始编号)。

你需要将每对 [ri, ci] 指定的行和列上的所有单元格的值加 1。

请你在执行完所有 indices 指定的增量操作后,返回矩阵中 「奇数值单元格」 的数目。

示例 1:

输入:n = 2, m = 3, indices = [[0,1],[1,1]]
输出:6
解释:最开始的矩阵是 [[0,0,0],[0,0,0]]。
第一次增量操作后得到 [[1,2,1],[0,1,0]]。
最后的矩阵是 [[1,3,1],[1,3,1]],里面有 6 个奇数。

示例 2:

输入:n = 2, m = 2, indices = [[1,1],[0,0]]
输出:0
解释:最后的矩阵是 [[2,2],[2,2]],里面没有奇数。

提示:

  • 1 <= n <= 50
  • 1 <= m <= 50
  • 1 <= indices.length <= 100
  • 0 <= indices[i][0] < n
  • 0 <= indices[i][1] < m

思路:
初始化矩阵填充0,遍历给定vector逐行逐列加1,遍历矩阵判断计数奇数的个数。

题解:

class Solution {
public:

    int oddCells(int n, int m, vector<vector<int>>& indices) {
        vector<vector<int>> a;
        int sum = 0;
        a.resize(n);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i].push_back(0);
            }
        }
        for (auto x: indices) {
            for (int i = 0; i < m; i++) {
                a[x[0]][i]++;
            }
            for (int i = 0; i < n; i++) {
                a[i][x[1]]++;
            }
        }
        for (auto x: a) {
            for (auto y: x) {
                if (y%2==1) {
                    sum++;
                }
            }
        }
        return sum;
    }
};

语法:
vector设置大小:

vector<vector<int>> arr;
arr.resize(5);		//设置arr长度为5;

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/cells-with-odd-values-in-a-matrix

汽车ECU诊断刷写和OTA升级中的验签和校验 阅读详情

相关推荐

【分布式系统学习】CAP原理详解

概述:互联网最重要任务莫过于海量数据处理,即大规模分布式系统,分布式是互联网的核心技术!!!如上所述,分布式系统是无法同时满足CAP三个特性的。1.Atomicity(原子性)一个事务中的所有操作,要么全部完成,要么全部不完成,不会在中间某个环节结束。事务在执行过程中发生错误,会被回滚到事务开始前的状态,就像这个事务从来没有执行过一样。2.Consistency(一致性)在事务开始之前和事务结束以后,数据库的完整性没有被破坏。3.Isolation(隔离性)

大龄烤红薯的博客 5024

leetcode1252. 奇数值单元格的数目C++

每日一题

sakeww的博客 362

华为手环实时心率数据导出到UWP项目中

hello大家好呀O(∩_∩)O最近在做毕设 其中有个小功能要用到实时心率数据。查找网上的资料发现只有小米手环的实时心率数据导出但是没有华为手环的,我试了华为手环但是并不能行得通哈哈哈。现在分享一下华为手环实时心率数据导出的代码。

apple_63713858的博客 1581

每日一题——LeetCode1252.奇数值单元格的数目

创建一个n x m的矩阵,初始化所有元素为0,对于indices中的每一对[ri,ci],将矩阵第ri行的所有数增加1,第ci列的所有数增加1.最后遍历矩阵得到奇数的数目。对于 indices中的每一对 [ri,ci],我们将 rows[ri]和 cols[ci]的值分别增加 1。用一个行数组 rows 和列数组 cols 分别记录每一行和每一列被增加的次数。位置 (x,y)位置的计数即为 rows[x]+cols[y]额外空间的算法来解决此问题吗?遍历矩阵找出奇数的数目。方法二 模拟空间优化。

weixin_52878347的博客 462

工控上位机开发学习路线与核心技术解析

工控上位机开发是工业自动化领域的关键技术,通过计算机软件实现对工业设备的监控与控制。其核心在于掌握工业通信协议(如Modbus、OPC UA)、数据处理算法和可视化开发三大能力。上位机系统需要高效解析设备通信协议,处理实时数据,并提供直观的人机交互界面。在智能制造浪潮下,掌握C#语言和工业协议开发能力成为工程师的核心竞争力。典型应用场景包括生产线监控、设备远程运维等。本文基于工业现场实践经验,详解从协议解析到界面优化的全链路开发要点,特别针对Modbus协议调优、WPF性能优化等高频问题提供解决方案。

weixin_30376083的博客 550

GPOPSII 对控制量变化率进行约束,避免控制量振荡

在这篇文章中,在GPOPSII中通过对控制量变化的约束,优化求解得到更平滑的控制量曲线,更符合真实控制约束。

Dannyfomer的博客 1870

leetcode 1252. 奇数值单元格的数目

https://leetcode-cn.com/problems/cells-with-odd-values-in-a-matrix/ 模拟大法好 class Solution: def oddCells(self, n: int, m: int, indices: List[List[int]]) -> int: grid=[[0 for i in range(m...

239

四足机器人机械结构设计:从腿型到驱动的全面解析

本文全面解析了四足机器人机械结构设计的核心要点。资深工程师老张深入探讨了并联腿与串联腿的选型策略、不同腿型布局对稳定性的影响,并详细对比了皮带轮与连杆驱动方式的优劣。文章结合实战经验,强调了足端设计、材料选择及整体结构轻量化等关键细节,为机器人开发者提供了从理论到实践的宝贵指导。

assembly8low的博客 632

leetcode:1252. 奇数值单元格的数目

给你一个 n 行 m 列的矩阵,最开始的时候,每个单元格中的值都是 0。 另有一个索引数组 indices,indices[i] = [ri, ci] 中的 ri 和 ci 分别表示指定的行和列(从 0 开始编号)。 你需要将每对 [ri, ci] 指定的行和列上的所有单元格的值加 1。 请你在执行完所有 indices 指定的增量操作后,返回矩阵中 「奇数值单元格」 的数目。 提示: 1 &l...

OceanStar的博客 199

Power domain 划分该如何下手

假如PD1比PD3更always on的话,我们只需要插入普通buffer即可,因为PD3 on,PD1也肯定是ON,PD1 off,PD3肯定时off,PD1能cover PD3的电源情况,因此使用普通buffer也可,但是处于省电角度,我们还是使用AO buffer;在我们做多power domain时,在切分power domain时,需要谨慎,稍有不慎,就会出现congestion以及timing问题,那问题来了,我们在切分power domain时有什么考究么,今天小编就和大家一起讨论讨论。

芯冰乐 207

在SAP系统中创建物料 860000000000000082(物料描述为“8680月球广寒宫坦克车”)时,系统报出了一个错误

摘要:SAP系统创建物料"8680月球广寒宫坦克车"时出现"C+020"错误,提示评估区域C916未在物料分类账中设置为生产性。解决方案需进入"会计-控制-产品成本控制-实际成本核算"路径,将评估区域C916手动设置为生产性状态。该操作需由具备权限的系统管理员或FICO顾问执行,建议操作前进行数据备份或在测试环境验证。完成设置后即可重新创建物料。

金牌架构师 391

python-leetcode-1252. 奇数值单元格的数目

可以使用一个直接模拟的方法,或者更优化的方法来解决这个问题。

Lucy_wzw的博客 513

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

LeetCode 1252. 奇数值单元格的数目

1. 题目 给你一个 n 行 m 列的矩阵,最开始的时候,每个单元格中的值都是 0。 另有一个索引数组 indices,indices[i] = [ri, ci] 中的 ri 和 ci 分别表示指定的行和列(从 0 开始编号)。 你需要将每对 [ri, ci] 指定的行和列上的所有单元格的值加 1。 请你在执行完所有 indices 指定的增量操作后,返回矩阵中 「奇数值单元格」 的数目。 来源...

Michael是个半路程序员 1080

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

深度学习工具包 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")

[LeetCode] 1252、奇数值单元格的数目

题目描述 给你一个 n 行 m 列的矩阵,最开始的时候,每个单元格中的值都是 0。另有一个索引数组 indices,indices[i] = [ri, ci] 中的 ri 和 ci 分别表示指定的行和列(从 0 开始编号)。你需要将每对 [ri, ci] 指定的行和列上的所有单元格的值加 1。请你在执行完所有 indices 指定的增量操作后,返回矩阵中 「奇数值单元格」 的数目。 输入:n =...

aift的专栏 265

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

1252.奇数值单元格的数目

给你一个n行m列的矩阵,最开始的时候,每个单元格中的值都是 0。 另有一个索引数组indices,indices[i] = [ri, ci]中的ri 和 ci 分别表示指定的行和列(从 0 开始编号)。 你需要将每对[ri, ci]指定的行和列上的所有单元格的值加 1。 请你在执行完所有indices指定的增量操作后,返回矩阵中 「奇数值单元格」 的数目。 示例...

Alex_Drag的博客 292

1252 奇数值单元格的数目

题目描述: 给你一个 n 行 m 列的矩阵,最开始的时候,每个单元格中的值都是 0。 另有一个索引数组 indices,indices[i] = [ri, ci] 中的 ri 和 ci 分别表示指定的行和列(从 0 开始编号)。 你需要将每对 [ri, ci] 指定的行和列上的所有单元格的值加 1。 请你在执行完所有 indices 指定的增量操作后,返回矩阵中 「奇数值单元格」 的数目。 示例 1: 输入:n = 2, m = 3, indices = [[0,1],[1,1]] 输出:6 解释:最开始

weixin_44171872的博客 193

【1252】奇数值的单元格的数目

题目(难度:简单): 代码思想: 单纯的暴力解决,需要注意的是区分indices的对行还是对列操作,这里是对行队列交替执行加1操作,用一个boolean类型的flag区分一下。 代码实现: public int oddCells(int n, int m, int[][] indices) { int[][] array = new int[n][m]; ...

泽阳Alex的博客 312

leetcode每日一题[1252. 奇数值单元格的数目]

给你一个 的矩阵,最开始的时候,每个单元格中的值都是 。另有一个二维索引数组 , 指向矩阵中的某个位置,其中 和 分别表示指定的行和列(从 开始编号)。对 所指向的每个位置,应同时执行下述增量操作:给你 、 和 。请你在执行完所有 指定的增量操作后,返回矩阵中 奇数值单元格 的数目。示例 1:输入: m = 2, n = 3, indices = [[0,1],[1,1]] 输出:6 解释:最开始的矩阵是 [[0,0,0],[0,0,0]]。 第一次增量操作后得到 [[1,2,1],[0,1,

weixin_44180026的博客 216

「 每日一练,快乐水题 」1252. 奇数值单元格的数目

另有一个二维索引数组indices,indices[i]=[ri,ci]指向矩阵中的某个位置,其中ri和ci分别表示指定的行和列(从0开始编号)。给你m、n和indices。请你在执行完所有indices指定的增量操作后,返回矩阵中奇数值单元格的数目。给你一个mxn的矩阵,最开始的时候,每个单元格中的值都是0。ri行上的所有单元格,加1。ci列上的所有单元格,加1。...

谁吃薄荷糖 393

LeetCode-1252、奇数值单元格的数目-简单

LeetCode-1252、奇数值单元格的数目-简单 给你一个n行m列的矩阵,最开始的时候,每个单元格中的值都是 0。 另有一个索引数组indices,indices[i] = [ri, ci]中的ri 和 ci 分别表示指定的行和列(从 0 开始编号)。 你需要将每对[ri, ci]指定的行和列上的所有单元格的值加 1。 请你在执行完所有indices指定的增量操作...

clover_my的博客 258

LeetCode—— 1252 奇数值单元格的数目

问题描述 给你一个n行m列的矩阵,最开始的时候,每个单元格中的值都是 0。 另有一个索引数组indices,indices[i] = [ri, ci]中的ri 和 ci 分别表示指定的行和列(从 0 开始编号)。 你需要将每对[ri, ci]指定的行和列上的所有单元格的值加 1。 请你在执行完所有indices指定的增量操作后,返回矩阵中 「奇数值单元格」 的数目。 ...

优快云的博客 173

LeetCode之1252. 奇数值单元格的数目

概要 题目来源链接:https://leetcode-cn.com/problems/cells-with-odd-values-in-a-matrix/ 难度:简单 类型:数组 题目 给你一个n行m列的矩阵,最开始的时候,每个单元格中的值都是 0。 另有一个索引数组indices,indices[i] = [ri, ci]中的ri 和 ci 分别表示指定的行和列(从 0 开始编号)。 你需要将每对[ri, ci]指定的行和列上的所有单元格的值加 1。 请你在执行完所有i...

二木成林 435

【1252. 奇数值单元格的数目】

来源:力扣(LeetCode)描述:给你一个 的矩阵,最开始的时候,每个单元格中的值都是 。另有一个二维索引数组 , 指向矩阵中的某个位置,其中 和 分别表示指定的行和列(从 0 开始编号)。对 所指向的每个位置,应同时执行下述增量操作:ri 行上的所有单元格,加 1 。ci 列上的所有单元格,加 1 。给你 、 和 。请你在执行完所有 指定的增量操作后,返回矩阵中 奇数值单元格 的数目。示例 1: 示例 2: 提示:方法一:直接模拟直接使用使用一个 的矩阵来存放操作的结果,对于 中的

Sugar_wolf的博客 193
上一篇: 1304. 和为零的N个唯一整数
下一篇: 232. 用栈实现队列
acticn
博客等级 码龄11年 0粉丝 34原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值