ZOJ Problem Set - 2857 Image Transformation
来源:互联网 发布:js基础数据类型 编辑:程序博客网 时间:2024/06/06 13:02
The image stored on a computer can be represented as a matrix of pixels. In the RGB (Red-Green-Blue) color system, a pixel can be described as a triplex integer numbers. That is, the color of a pixel is in the format "r g b" where r, g and b are integers ranging from 0 to 255(inclusive) which represent the Red, Green and Blue level of that pixel.
Sometimes however, we may need a gray picture instead of a colorful one. One of the simplest way to transform a RGB picture into gray: for each pixel, we set the Red, Green and Blue level to a same value which is usually the average of the Red, Green and Blue level of that pixel (that is (r + g + b)/3, here we assume that the sum of r, g and b is always dividable by 3).
You decide to write a program to test the effectiveness of this method.
Input
The input contains multiple test cases!
Each test case begins with two integer numbers N and M (1 <= N, M <= 100) meaning the height and width of the picture, then three N * M matrices follow; respectively represent the Red, Green and Blue level of each pixel.
A line with N = 0 and M = 0 signals the end of the input, which should not be proceed.
Output
For each test case, output "Case #:" first. "#" is the number of the case, which starts from 1. Then output a matrix of N * M integers which describe the gray levels of the pixels in the resultant grayed picture. There should be N lines with M integers separated by a comma.
Sample Input
2 2
1 4
6 9
2 5
7 10
3 6
8 11
2 3
0 1 2
3 4 2
0 1 2
3 4 3
0 1 2
3 4 4
0 0
Sample Output
Case 1:
2,5
7,10
Case 2:
0,1,2
3,4,3
Author: ZHOU, Yuan
Source: Zhejiang Provincial Programming Contest 2007
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
const int maxn=105;
const int maxm=105;
int a[3][maxn][maxm],b[maxn][maxm];
//g[maxn][maxm],b[maxn][maxm];
int main()
{
int n,m,i,j,k;
int c=0;
while(scanf("%d%d",&n,&m)&&n&&m)
{
//memset(a,0,sizeof(a));
c++;
for(k=0;k<3;k++)
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
scanf("%d",&a[k][i][j]);
}
printf("Case %d:\n",c);
for(i=0;i<n;i++)
for(j=0;j<m;j++)
{
b[i][j]=(a[0][i][j]+a[1][i][j]+a[2][i][j])/3;
if(j<m-1)
printf("%d,",b[i][j]);
else printf("%d\n",b[i][j]);
}
}
return 0;
}
- ZOJ Problem Set - 2857 Image Transformation
- ZOJ Problem Set - 2857 Image Transformation
- zoj 2857 Image Transformation
- ZOJ 2857 Image Transformation
- zoj 2857 Image Transformation
- ZOJ 2857 Image Transformation
- ZOJ 2857Image Transformation
- zoj-【2857 Image Transformation 】
- zoj 2857 Image Transformation水题
- ZOJ 2857: Image Transformation 【vector】
- Solution of ZOJ 2857 Image Transformation
- ZOJ 2857 Image Transformation(像素)
- ZOJ Problem Set - 2060
- ZOJ Problem Set - 2972
- ZOJ Problem Set - 1037
- ZOJ Problem Set - 1048
- ZOJ Problem Set - 1049
- ZOJ Problem Set - 1051
- 1月21日总结
- php当中的观察者模式,在laravel框架中有用到
- Yii2 使用三 使用数据库
- IOS资源适配
- 对STM32的NVIC_PriorityGroupConfig使用及优先级分组方式理解
- ZOJ Problem Set - 2857 Image Transformation
- android 任务和返回栈
- iOS开发——加载、滑动翻阅大量图片解决方案详解
- Android四大组建之Content Provider 基础篇
- 创建ios推送证书 pem格式
- 高级图形编程(基于opengl)9
- 余秀华诗句杂抄
- 话说,姚贝娜去世为何会引起轰动
- Insertion Sort List Leetcode Python