简答题 偏难
#7170

图像处理 给定n行m列的图像各像素点的灰度值,要求用如下方法对其进行模糊化处理: 1. 四周最外侧的像素点灰度值不变; 2. 中间各像素点新灰度值为该像素点及其…

图像处理

给定n行m列的图像各像素点的灰度值,要求用如下方法对其进行模糊化处理:

1. 四周最外侧的像素点灰度值不变;

2. 中间各像素点新灰度值为该像素点及其上下左右相邻四个像素点原灰度值的平均(舍入到最接近的整数)。

时间限制:1000

内存限制:65536

输入

第一行包含两个整数n和m,表示图像包含像素点的行数和列数。1 <= n <= 100,1 <= m <= 100。 接下来n行,每行m个整数,表示图像的每个像素点灰度。相邻两个整数之间用单个空格隔开,每个元素均在0~255之间。

输出

n行,每行m个整数,为模糊处理后的图像。相邻两个整数之间用单个空格隔开。

样例输入

4 5
100 0 100 0 50
50 100 200 0 0
50 50 100 100 200
100 100 50 50 100

样例输出

100 0 100 0 50
50 80 100 60 0
50 80 100 90 200
100 100 50 50 100
未登录也能判分,登录后才会记录
答案与解析
正确答案:<pre class="brush:cpp;toolbar:false">#include &lt;cmath&gt; #include &lt;iostream&gt; using namespace std; const int N = 100 + 10; int a[N][N], b[N][N]; int main() {   int n, m;   cin &gt;&gt; n &gt;&gt; m;   for (int i = 1; i &lt;= n; i++) {     for (int j = 1; j &lt;= m; j++) {       cin &gt;&gt; a[i][j];       b[i][j] = a[i][j];     }   }   for (int i = 1; i &lt;= n; i++) {     for (int j = 1; j &lt;= m; j++) {       if (i == n || i == 1 || j == m || j == 1)         continue;       else {         double sum =             a[i][j] + a[i - 1][j] + a[i + 1][j] + a[i][j - 1] + a[i][j + 1];         sum /= 5;         b[i][j] = int(round(sum));       }     }   }   for (int i = 1; i &lt;= n; i++) {     for (int j = 1; j &lt;= m; j++) {       if (j == 1)         cout &lt;&lt; b[i][j];       else         cout &lt;&lt; ' ' &lt;&lt; b[i][j];     }     cout &lt;&lt; endl;   } }</pre>
这道题暂未补解析。