当前位置:网站首页>733. image rendering
733. image rendering
2022-06-27 03:32:00 【Blueberry man】
It can be understood as width traversal of graph
If the colors are the same, exit directly to prevent infinite recursion
class Solution {
public:
class pos
{
public:
int x_;
int y_;
pos(int x, int y):x_(x),y_(y){}
};
vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {
if(image.empty())
return image;
int standard_color = image.at(sr).at(sc);
if(color == standard_color)
return image;
queue<pos>to_use;
to_use.push(pos(sr,sc));
image.at(sr).at(sc) = color;
while(!to_use.empty())
{
auto cur_pos = to_use.front();
to_use.pop();
if(cur_pos.x_-1 >=0 && image.at(cur_pos.x_-1).at(cur_pos.y_)==standard_color)
{
image.at(cur_pos.x_-1).at(cur_pos.y_) = color;
to_use.push(pos(cur_pos.x_-1, cur_pos.y_));
}
if(cur_pos.x_+1 <(int)image.size() && image.at(cur_pos.x_+1).at(cur_pos.y_)==standard_color)
{
image.at(cur_pos.x_+1).at(cur_pos.y_) = color;
to_use.push(pos(cur_pos.x_+1, cur_pos.y_));
}
if(cur_pos.y_-1 >=0 && image.at(cur_pos.x_).at(cur_pos.y_-1)==standard_color)
{
image.at(cur_pos.x_).at(cur_pos.y_-1) = color;
to_use.push(pos(cur_pos.x_, cur_pos.y_-1));
}
if(cur_pos.y_+1<(int)image[0].size() && image.at(cur_pos.x_).at(cur_pos.y_+1)==standard_color)
{
image.at(cur_pos.x_).at(cur_pos.y_+1) = color;
to_use.push(pos(cur_pos.x_, cur_pos.y_+1));
}
}
return image;
}
};
边栏推荐
- [array] sword finger offer II 012 The sum of left and right subarrays is equal | sword finger offer II 013 Sum of two dimensional submatrix
- 清华&华为等 综述 | 语义通信:原则与挑战
- Pat grade a 1026 table tennis
- 2016Analyzing the Behavior of Visual Question Answering Models
- fplan-Powerplan实例
- Il manque beaucoup de fichiers et de répertoires tels que scripts pendant et après l'installation d'anaconda3
- 使用promise的基本功能【四、Promise源码】
- Learning Tai Chi Maker - mqtt Chapter 2 (II) esp8266 QoS application
- Quicksand painting simulator source code
- Agile development - self use
猜你喜欢

fplan-电源规划
![[array] sword finger offer II 012 The sum of left and right subarrays is equal | sword finger offer II 013 Sum of two dimensional submatrix](/img/e4/7bae2a109dcf5e2a8f032e73b89479.png)
[array] sword finger offer II 012 The sum of left and right subarrays is equal | sword finger offer II 013 Sum of two dimensional submatrix
![Promise [II. Promise source code] [detailed code comments / complete test cases]](/img/ac/abf3181fa7b3345efcc9abc046cea5.png)
Promise [II. Promise source code] [detailed code comments / complete test cases]

一文教你Kali信息收集

2016Analyzing the Behavior of Visual Question Answering Models

2020:MUTANT: A Training Paradigm for Out-of-Distribution Generalizationin Visual Question Answering

2021:AdaVQA: Overcoming Language Priors with Adapted Margin Cosine Loss∗自适应的边缘余弦损失解决语言先验

PAT甲级 1024 Palindromic Number

1. Project preparation and creation

【数组】剑指 Offer II 012. 左右两边子数组的和相等 | 剑指 Offer II 013. 二维子矩阵的和
随机推荐
Promise [II. Promise source code] [detailed code comments / complete test cases]
Uni-app 之uParse 富文本解析 完美解析富文本!
Pat grade a 1021 deep root
How do I simplify the development of interfaces in open source systems?
Pat grade a 1023 have fun with numbers
455. distribute biscuits [distribution questions]
Test the respective roles of nohup and &
2022年氯碱电解工艺试题及答案
Brief introduction of 228 dropout methods of pytorch and fast implementation of dropblock with 4 lines of code based on dropout
2021:Greedy Gradient Ensemble for Robust Visual Question Answering
Solve the problem of error reporting in cherry pick submission
Pat grade a 1018 public bike management
2021:Beyond Question-Based Biases:Assessing Multimodal Shortcut Learning in Visual Question Answeri
2022 Chinese pastry (Advanced) recurrent training question bank and online simulation test
2019LXMERT:Learning Cross-Modality Encoder Representations from Transformers
Learning Tai Chi Maker - mqtt Chapter 2 (II) esp8266 QoS application
【promise一】promise的介绍与手撸的关键问题
Anaconda3 is missing a large number of files during and after installation, and there are no scripts and other directories
PAT甲级 1019 General Palindromic Number
Common sense of Apple's unique map architecture