当前位置:网站首页>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;
}
};
边栏推荐
- Yiwen teaches you Kali information collection
- 2022中式面点师(高级)复训题库及在线模拟考试
- Semantic version 2.0.0
- 实践 DevOps 时,可能面临的六大挑战
- 人群模拟
- Pat class a 1024 palindromic number
- 2021:Zero-shot Visual Question Answering using Knowledge Graphs使用知识图的零次视觉问答
- IDEA中好用的插件
- Learn Tai Chi Maker - mqtt (VI) esp8266 releases mqtt message
- Stack overflow vulnerability
猜你喜欢

How does source insight (SI) display the full path? (do not display omitted paths) (turn off trim long path names with ellipses)

2019LXMERT:Learning Cross-Modality Encoder Representations from Transformers

Pat grade a 1026 table tennis

静态时序分析-OCV和time derate

学习太极创客 — MQTT(八)ESP8266订阅MQTT主题

手撸promise【二、Promise源码】【代码详细注释/测试案例完整】

2021:Graphhopper: Multi-Hop Scene Graph Reasoning for Visual Question Answering

Yiwen teaches you Kali information collection

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

2019LXMERT:Learning Cross-Modality Encoder Representations from Transformers
随机推荐
PAT甲级 1026 Table Tennis
Anaconda3 is missing a large number of files during and after installation, and there are no scripts and other directories
Yiwen teaches you Kali information collection
Test the respective roles of nohup and &
I found a JSON visualization tool artifact. I love it!
servlet与JSP期末复习考点梳理 42问42答
学习太极创客 — MQTT 第二章(一)QoS 服务质量等级
Paddlepaddle 19 dynamically modify the last layer of the model
使用promise的基本功能【四、Promise源码】
fplan-电源规划
2021:AdaVQA: Overcoming Language Priors with Adapted Margin Cosine Loss∗自适应的边缘余弦损失解决语言先验
再探Handler(下)(Handler核心原理最全解析)
Learn Tai Chi Maker - mqtt (VI) esp8266 releases mqtt message
学习太极创客 — MQTT(六)ESP8266 发布 MQTT 消息
PAT甲级 1023 Have Fun with Numbers
我是怎样简化开源系统中的接口的开发的?
Pat grade a 1023 have fun with numbers
Promise [II. Promise source code] [detailed code comments / complete test cases]
Stack overflow vulnerability
Geometric distribution (a discrete distribution)