当前位置:网站首页>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;
}
};
边栏推荐
- 【Copy攻城狮日志】飞浆学院强化学习7日打卡营-学习笔记
- 浅谈外挂常识和如何防御
- ConnectionRefusedError: [Errno 111] Connection refused问题解决
- sbl_init.asm-适合在编辑模式下看
- 基于PyTorch的FCN-8s语义分割模型搭建
- 审稿意见回复
- Deep Learning Theory - Overfitting, Underfitting, Regularization, Optimizers
- Copy Siege Lion 5-minute online experience MindIR format model generation
- 度量学习(Metric learning)—— 基于分类损失函数(softmax、交叉熵、cosface、arcface)
- 度量学习(Metric learning、损失函数、triplet、三元组损失、fastreid)
猜你喜欢

安装pyspider后运行pyspider all后遇到的问题

动手学深度学习_多层感知机

中国联通、欧莱雅和钉钉都在争相打造的秘密武器?虚拟IP未来还有怎样的可能

TensorRT 5 初步认识

动手学深度学习__张量

PP-LiteSeg

深度学习理论 —— 初始化、参数调节
![[Deep Learning Diary] Day 1: Hello world, Hello CNN MNIST](/img/06/6f49260732e5832edae2ec80aafc99.png)
[Deep Learning Diary] Day 1: Hello world, Hello CNN MNIST

MNIST Handwritten Digit Recognition - Building a Perceptron from Zero for Two-Classification

Image-Adaptive YOLO for Object Detection in Adverse Weather Conditions
随机推荐
"A minute" Copy siege lion log 】 【 run MindSpore LeNet model
腾讯、网易纷纷出手,火到出圈的元宇宙到底是个啥?
Attention Is All You Need(Transformer)
Copy攻城狮5分钟在线体验 MindIR 格式模型生成
度量学习(Metric learning、损失函数、triplet、三元组损失、fastreid)
MNIST Handwritten Digit Recognition - Lenet-5's First Commercial Grade Convolutional Neural Network
tensorRT教程——tensor RT OP理解(实现自定义层,搭建网络)
亚马逊云科技 Build On 2022 - AIot 第二季物联网专场实验心得
PyTorch
基于BiGRU和GAN的数据生成方法
Image-Adaptive YOLO for Object Detection in Adverse Weather Conditions
[Deep Learning Diary] Day 1: Hello world, Hello CNN MNIST
2020-10-19
【CV-Learning】Convolutional Neural Network
【论文阅读】TransReID: Transformer-based Object Re-Identification
【CV-Learning】Object Detection & Instance Segmentation
Data reading in yolov3 (1)
【深度学习日记】第一天:Hello world,Hello CNN MNIST
Pytest常用插件
postgres recursive query