zoj 2857 Image Transformation
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 <= 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
#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的更多相关文章
- ZOJ 2671 Cryptography 矩阵乘法+线段树
B - Cryptography Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Subm ...
- (七)Transformation和action详解-Java&Python版Spark
Transformation和action详解 视频教程: 1.优酷 2.YouTube 什么是算子 算子是RDD中定义的函数,可以对RDD中的数据进行转换和操作. 算子分类: 具体: 1.Value ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- 线性分式变换(linear fractional transformation)
线性分式变换(linear fractional transformation)的名称来源于其定义的形式:(ax+b)/(cx+d),其中分子分母是线性的,然后最外层是一个分式形式,所以叫做这个名字, ...
- OLE DB Command transformation 用法
OLE DB Command transformation component 能够引用参数,逐行调用sqlcommand,This transformation is typically used ...
- OpenCASCADE General Transformation
OpenCASCADE General Transformation eryar@163.com Abstract. OpenCASCADE provides a general transforma ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
随机推荐
- COPY, RETAIN, ASSIGN , READONLY , READWRITE,STRONG,WEAK,NONATOMIC整理--转
copy:建立一个索引计数为1的对象,然后释放旧对象 对NSString 对NSString 它指出,在赋值时使用传入值的一份拷贝.拷贝工作由copy方法执行,此属性只对那些实行了NSCopying协 ...
- Backbone.js入门教程第二版笔记(3)
视图渲染 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <titl ...
- Centos 6.5安装MySQL-python
报错信息: Using cached MySQL-python-1.2.5.zip Complete output from command python setup.py egg_info: ...
- gbk编码文件传输json实例
cline.php <?php $str='此地无银三百两'; $str = iconv('gbk', 'utf-8', $str); //Json只支持utf-8编码,如果不进行转码的话,服务 ...
- springboot之读取配置文件
1.propertie配置读取数据 /** * 通过value取配置文件中的数据 */ @Component @PropertySource(value = {"config/db-conf ...
- 【转】一篇文章,教你学会Git
一篇文章,教你学会Git 在日常工作中,经常会用到Git操作.但是对于新人来讲,刚上来对Git很陌生,操作起来也很懵逼.本篇文章主要针对刚开始接触Git的新人,理解Git的基本原理,掌握常用的一些命令 ...
- Excuse me?这个前端面试在搞事!
金三银四搞事季,前端这个近年的热门领域,搞事气氛特别强烈,我朋友小伟最近就在疯狂面试,遇到了许多有趣的面试官,有趣的面试题,我来帮这个搞事 boy 转述一下. 以下是我一个朋友的故事,真的不是我. f ...
- Selenium2(WebDriver)开发环境搭建(java版)
一.开发环境 1.JDK 2.Eclipse 3.Firefox 28.0 4.selenium-java-2.44.0.zip 解压后: 5.selenium-server-standalone-2 ...
- JavaScript 声明全局变量与局部变量
一.JavaScript 声明全局变量的三种方式: 声明方式一: 使用var(关键字)+变量名(标识符)的方式在function外部声明,即为全局变量,否则在function声明的是局部变量.该方式即 ...
- COGS 1361. 树
★ 输入文件:treed.in 输出文件:treed.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 在一个凉爽的夏夜,xth和rabbit来到花园里砍树.为啥 ...