当前位置:网站首页>LeetCode_22_Apr_4th_Week
LeetCode_22_Apr_4th_Week
2022-08-04 05:30:00 【KuoGavin】
真真是天有不测风云,中间亲人出了点事情就没有精力继续刷题了。万幸是这个时间节点还可以多照顾她,现在情况也稳定下来了,环境也差不多配置好了,再捡回来好了。祝大家都健健康康,生活如意!
April 25th : 398. 随机数索引
April 26th : 883. 三维形体投影面积
April 25th : 398. 随机数索引
主要是随机种子的设置和使用:
srand((unsigned)time(NULL));
rand()%num //等概率获取0~num-1之间的任一数字
解题代码如下:
class Solution {
public:
Solution(vector<int>& nums) {
srand((unsigned)time(NULL));
for(int i = 0; i < nums.size(); ++i) keys[nums[i]].push_back(i);
}
int pick(int target) {
return keys[target][rand()%keys[target].size()];
}
private:
unordered_map<int, vector<int>> keys;
};
评论这里有个蓄水池原理,挺有意思的,效率也比上述方法更高
class Solution {
public:
vector<int> res;
Solution(vector<int>& nums) {
res = nums;
}
int pick(int target) {
int c = 0, index = 0;
for(int i = 0;i < res.size();i++)
if(res[i] == target){
c++;
if(rand() % c == 0) index = i;
}
return index;
}
};
April 26th :April 26th : 883. 三维形体投影面积
该题就是面积为,每列最大值的和+每行最大值的和+非0行列数目,解题代码如下:
class Solution {
public:
int projectionArea(vector<vector<int>>& grid) {
int overLookView = 0, leftLookView = 0, rightLookView = 0;
int rowMax = 0, colMax = 0; //复用行列的遍历,只需交换i,j的位置即可
for(int i = 0; i < grid.size(); ++i) {
rowMax = 0, colMax = 0;
for(int j = 0; j < grid[i].size(); ++j) {
overLookView += grid[i][j] ? 1 : 0;
rowMax = max(grid[i][j], rowMax);
colMax = max(grid[j][i], colMax);
}
leftLookView += rowMax;
rightLookView += colMax;
}
return overLookView + leftLookView + rightLookView;
}
};
边栏推荐
- Introduction to Convolutional Neural Networks
- TensorFlow2 study notes: 8. tf.keras implements linear regression, Income dataset: years of education and income dataset
- 动手学深度学习__张量
- 空洞卷积
- 投稿相关
- Android foundation [Super detailed android storage method analysis (SharedPreferences, SQLite database storage)]
- 多层LSTM
- Linear Regression 02---Boston Housing Price Prediction
- [CV-Learning] Convolutional Neural Network Preliminary Knowledge
- MNIST handwritten digit recognition, sorted by from two to ten
猜你喜欢

【论文阅读】Anchor-Free Person Search

Linear Regression 02---Boston Housing Price Prediction

图像形变(插值方法)

【论文阅读】TransReID: Transformer-based Object Re-Identification

Transformer

动手学深度学习__数据操作

No matching function for call to ‘RCTBridgeModuleNameForClass‘

动手学深度学习_线性回归
![[CV-Learning] Linear Classifier (SVM Basics)](/img/94/b48e34b2c215ca47f8ca25ce97547e.png)
[CV-Learning] Linear Classifier (SVM Basics)

Deep Learning Theory - Initialization, Parameter Adjustment
随机推荐
Golang environment variable settings (2)--GOMODULE & GOPROXY
基于BiGRU和GAN的数据生成方法
0, deep learning 21 days learning challenge 】 【 set up learning environment
ValueError: Expected 96 from C header, got 88 from PyObject
target has libraries with conflicting names: libcrypto.a and libssl.a.
postgres recursive query
图像形变(插值方法)
Deep Adversarial Decomposition: A Unified Framework for Separating Superimposed Images
2020-10-19
tensorRT5.15 使用中的注意点
CSDN大礼包--高校圆桌派大礼包
The difference between oracle temporary table and pg temporary table
The second official example analysis of the MOOSE platform - about creating a Kernel and solving the convection-diffusion equation
MNIST手写数字识别 —— ResNet-经典卷积神经网络
代码庆端午--粽你心意
浅谈外挂常识和如何防御
【五一专属】阿里云ECS大测评#五一专属|向所有热爱分享的“技术劳动者”致敬#
Machine Learning - Processing of Text Labels for Classification Problems (Feature Engineering)
latex-写论文时一些常用设置
TensorRT 5 初步认识