leetcode661
vector<vector<int>> imageSmoother(vector<vector<int>>& M) {
const int N = ;
vector<vector<int>> V;
for (int i = ; i < M.size(); i++)//x范围M.size()=3
{
vector<int> m1 = M[i];
vector<int> m2;
for (int j = ; j < m1.size(); j++)//y范围m1.size()=3
{
int m0 = m1[j];
//根据i和j找到周边8个节点
int sum = ;
int count = ;
for (int x = i - ; x <= i + ; x++)
{
for (int y = j - ; y <= j + ; y++)
{
if (x >= && x <= M.size() - && y >= && y <= m1.size() - )
{
sum += M[x][y];
count++;
}
}
}
int m = sum / count;
m2.push_back(m);
}
V.push_back(m2);
}
return V;
}
leetcode661的更多相关文章
- [Swift]LeetCode661. 图片平滑器 | Image Smoother
Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...
- LeetCode661图片平滑器
题目描述:包含整数的二维矩阵 M 表示一个图片的灰度.你需要设计一个平滑器来让每一个单元的灰度成为平均灰度 (向下舍入) ,平均灰度的计算是周围的8个单元和它本身的值求平均,如果周围的单元格不足八个, ...
- Leetcode661.Image Smoother图片平滑器
包含整数的二维矩阵 M 表示一个图片的灰度.你需要设计一个平滑器来让每一个单元的灰度成为平均灰度 (向下舍入) ,平均灰度的计算是周围的8个单元和它本身的值求平均,如果周围的单元格不足八个,则尽可能多 ...
随机推荐
- Python 正则表达式匹配小数
不废话,直接上表达式 (\d+(\.\d+)?) 如: import re find_float = lambda x: re.search("\d+(\.\d+)?",x) .g ...
- tensorflow实现Minist手写体识别
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data #下载MINIST数据集mnist ...
- shell获取ip地址
Mac: $ ifconfig en0|awk -F"[ ]+" '/inet/{print $2}' fe80::a211:9bff:fe15:%en0 192.168.0.10 ...
- 51nod 1163 贪心
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1163 1163 最高的奖励 基准时间限制:1 秒 空间限制:131072 ...
- Vue在HTML页面中的脚手架
<script src="assets/js/vue.js"></script> <script src="assets/js/vue-re ...
- hbase_异常_03_java.io.EOFException: Premature EOF: no length prefix available
一.异常现象 更改了hadoop的配置文件:core-site.xml 和 mapred-site.xml 之后,重启hadoop 和 hbase 之后,发现hbase日志中抛出了如下异常: ...
- .NET和Docker ,比翼双飞
DockerCon 2019本周将在旧金山举行 ,DockerCon 是从业者.贡献者.维护者.开发者和容器生态系统学习.网络和创新的一站式活动. .NET 团队博客发布了<一起使用.NET和D ...
- BEC listen and translation exercise 9
You will do foolish things, but do them with enthusiasm. 你难免会做傻事,但要做,就做得满怀激情. In addition, there sho ...
- RedHat5.8 编译内核驱动 合成initrd.img
/******************************************************************* * RedHat5.8 编译内核驱动 合成initrd.img ...
- bzoj 4299 Codechef FRBSUM
定义一个集合的神秘数为不能表示成这个集合的某个子集和的最小正整数,给一个数列,多次求区间神秘数 $n \leq 100000$ sol: 考虑这个神秘数的性质,可以发现,如果神秘数是 $x$,那么 $ ...