当前位置:网站首页>733. 图像渲染
733. 图像渲染
2022-06-27 03:29:00 【蓝莓侠】
可以理解为图的宽度遍历
下面如果颜色相同就直接退出是防止出现无限递归
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;
}
};
边栏推荐
- 2021:Zero-shot Visual Question Answering using Knowledge Graphs使用知识图的零次视觉问答
- Geometric distribution (a discrete distribution)
- Method of decoding iPhone certificate file
- 【promise一】promise的介绍与手撸的关键问题
- Brief introduction of 228 dropout methods of pytorch and fast implementation of dropblock with 4 lines of code based on dropout
- The use and introduction of pytorch 23 hook and the implementation of plug and play dropblock based on hook
- fplan-布局
- Implementation of window encryption shell
- pytorch_ grad_ Cam -- visual Library of class activation mapping (CAM) under pytorch
- 1. Project preparation and creation
猜你喜欢

PAT甲级 1026 Table Tennis

学习太极创客 — MQTT(七)MQTT 主题进阶

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

promise源码-class版本【三、Promise源码】【代码详细注释/测试案例完整】

JMeter distributed pressure measurement

2021:Passage Retrieval for Outside-KnowledgeVisual Question Answering通道检索的外部知识视觉问答

Nacos调用微服务两个问题:1.Load balancer does not contain an instance for the service 2.Connection refused

TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘

SAI钢笔工具如何使用,入门篇

Pat grade a 1021 deep root
随机推荐
Servlet and JSP final review examination site sorting 42 questions and 42 answers
Usage knowledge of mobile phones in new fields
对数器
敏捷开发篇--Agile Development-自用
Semantic version 2.0.0
Calculation of average wind direction and speed (unit vector method)
455. distribute biscuits [distribution questions]
PAT甲级 1023 Have Fun with Numbers
Pat grade a 1020 tree Traversals
Learn Tai Chi maker mqtt (IX) esp8266 subscribe to and publish mqtt messages at the same time
Resnet152 pepper pest image recognition 1.0
Yiwen teaches you Kali information collection
fplan-布局
超级详细,2 万字详解,吃透 ES!
2022中式面点师(高级)复训题库及在线模拟考试
测试nohup和&的各自作用
SAI钢笔工具如何使用,入门篇
清华&华为等 综述 | 语义通信:原则与挑战
Human soberness: bottom logic and top cognition
Stack overflow vulnerability