Image Transformation


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 <= NM <= 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

 #include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main(){
vector<int> r, g, b;
int n, m, test = , i, t;
while(cin >> n >> m){
if(n == && m == )
break;
test++;
r.clear();
g.clear();
b.clear();
for(i = ; i < n * m; i++){
cin >> t;
r.push_back(t);
}
for(i = ; i < n * m; i++){
cin >> t;
g.push_back(t);
}
for(i = ; i < n * m; i++){
cin >> t;
b.push_back(t);
}
cout << "Case " << test << ":" << endl;
for(i = ; i < n * m; i++){
cout << (r[i] + g[i] + b[i]) / ;
if((i + ) % m == )
cout << endl;
else
cout << ",";
}
}
//system("pause");
return ;
}

zoj 2857 Image Transformation的更多相关文章

  1. ZOJ 2671 Cryptography 矩阵乘法+线段树

    B - Cryptography Time Limit:5000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Subm ...

  2. (七)Transformation和action详解-Java&Python版Spark

    Transformation和action详解 视频教程: 1.优酷 2.YouTube 什么是算子 算子是RDD中定义的函数,可以对RDD中的数据进行转换和操作. 算子分类: 具体: 1.Value ...

  3. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  4. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  5. 线性分式变换(linear fractional transformation)

    线性分式变换(linear fractional transformation)的名称来源于其定义的形式:(ax+b)/(cx+d),其中分子分母是线性的,然后最外层是一个分式形式,所以叫做这个名字, ...

  6. OLE DB Command transformation 用法

    OLE DB Command transformation component 能够引用参数,逐行调用sqlcommand,This transformation is typically used ...

  7. OpenCASCADE General Transformation

    OpenCASCADE General Transformation eryar@163.com Abstract. OpenCASCADE provides a general transforma ...

  8. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  9. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

随机推荐

  1. 74LVC2G241双缓冲3态驱动器

  2. 搜狐前端css常用命名

  3. hdu 2604 Queuing dp找规律 然后矩阵快速幂。坑!!

    http://acm.hdu.edu.cn/showproblem.php?pid=2604 这题居然O(9 * L)的dp过不了,TLE,  更重要的是找出规律后,O(n)递推也过不了,TLE,一定 ...

  4. 基于CentOS6.5下snort+barnyard2+base的入侵检测系统的搭建(图文详解)(博主推荐)

    为什么,要写这篇论文? 是因为,目前科研的我,正值研三,致力于网络安全.大数据.机器学习研究领域! 论文方向的需要,同时不局限于真实物理环境机器实验室的攻防环境.也不局限于真实物理机器环境实验室的大数 ...

  5. UVA6531Go up the ultras

    链接 这题意甚是难懂..当且峰值为h 如果他能为ultras 需要满足条件 d>=15W d满足它到任意一个比它高的点须经过h-d这个点 通俗一点来说,如果这个点满足条件 就找离他最近的一个&l ...

  6. Android利用已有控件实现自定义控件

    Android控件的基本介绍及使用自定义控件的意义         Android 本身提供了很多控件,自定义控件在android中被广泛运用,自定义控件给了我们很大的方便.比如说,一个视图为imag ...

  7. COGS 942. [東方S3] 比那名居天子

    Problem 1 比那名居天子(tenshi.cpp/c/pas) 题目描述 在幻想乡,比那名居天子是管理着『要石』的天人.『要石』是能够引发和镇压地震的存在,当然也可以用来改变地形.因为在幻想乡引 ...

  8. mybatis获取存储过程返回结果

    获取存储过程返回结果 代码: // Map<String,Object> map = new HashMap<String,Object>(); map.put("i ...

  9. sqlserver 分页问题

    1.top 主要是在sql server 2000中使用,效率较差 2.row_number函数 这种方法是sql server 2005以后,支持了row_number函数后,才开始使用的. dec ...

  10. BZOJ3940: [Usaco2015 Feb]Censoring (AC自动机)

    题意:在文本串上删除一些字符串 每次优先删除从左边开始第一个满足的 删除后剩下的串连在一起重复删除步骤 直到不能删 题解:建fail 用栈存当前放进了那些字符 如果可以删 fail指针跳到前面去 好菜 ...