当前位置:网站首页>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;
}
};
边栏推荐
- ValueError: Expected 96 from C header, got 88 from PyObject
- 动手学深度学习_卷积神经网络CNN
- Deep Learning Theory - Initialization, Parameter Adjustment
- 【论文阅读】Multi-View Spectral Clustering with Optimal Neighborhood Laplacian Matrix
- Rules.make-适合在编辑模式下看
- TensorFlow2 study notes: 8. tf.keras implements linear regression, Income dataset: years of education and income dataset
- TensorFlow: tf.ConfigProto() and Session
- 光条中心提取方法总结(一)
- MNIST Handwritten Digit Recognition - From Perceptrons to Convolutional Neural Networks
- 腾讯、网易纷纷出手,火到出圈的元宇宙到底是个啥?
猜你喜欢
arm-3-中断体系结构
AWS uses EC2 to reduce the training cost of DeepRacer: DeepRacer-for-cloud practical operation
Deep Adversarial Decomposition: A Unified Framework for Separating Superimposed Images
Lee‘s way of Deep Learning 深度学习笔记
Data reading in yolov3 (1)
Attention Is All You Need(Transformer)
MAE 论文《Masked Autoencoders Are Scalable Vision Learners》
makefile基础学习
【深度学习日记】第一天:Hello world,Hello CNN MNIST
"A minute" Copy siege lion log 】 【 run MindSpore LeNet model
随机推荐
target has libraries with conflicting names: libcrypto.a and libssl.a.
Rules.make-适合在编辑模式下看
PostgreSQL schema (Schema)
Install Minikube Cluster in AWS-EC2
动手学深度学习_softmax回归
Machine Learning - Processing of Text Labels for Classification Problems (Feature Engineering)
MFC 打开与保存点云PCD文件
arm-3-中断体系结构
TypeError: load() missing 1 required positional argument: ‘Loader‘
Pytest常用插件
度量学习(Metric learning)—— 基于分类损失函数(softmax、交叉熵、cosface、arcface)
[Copy Siege Lion Log] Flying Pulp Academy Intensive Learning 7-Day Punch Camp-Study Notes
TensorRT 5 初步认识
光条中心提取方法总结(一)
DeblurGAN-v2: Deblurring (Orders-of-Magnitude) Faster and Better 图像去模糊
【代码学习】
PyTorch
典型CCN网络——efficientNet(2019-Google-已开源)
No matching function for call to 'RCTBridgeModuleNameForClass'
Copy Siege Lions "sticky" to AI couplets