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 ...
随机推荐
- ADB over Wi-Fi
ADB over Wi-Fi 1.root $adb root 2.设置tcp端口并重启tcpip服务 $adb shell setprop persist.adb.tcp.port &&am ...
- Java 修改编码格式的几种方式
1.工作空间 workspase Window→Preferences→General→Workspace→Text file encoding→other→UTF-8 2.项目编码格式 右键项目名→ ...
- 动手实现 React-redux(二):结合 context 和 store
既然要把 store 和 context 结合起来,我们就先构建 store.在 src/index.js 加入之前创建的 createStore 函数,并且构建一个 themeReducer 来生成 ...
- 列表、margin和padding的探讨、标签的分类
一.列表 列表分为无序列表.有序列表和自定义列表 1.无序列表 <ul></ul> 1).内部必须有子标签,<li></li> 2).ul天生自带内 ...
- Oracle 11g r2 Enterprise Manager (EM) 中文页面调整为英文页面
Oracle 11g r2 Enterprise Manager (EM) 在中文语言环境下, 部分功能(如包含时间的查询数据库实例: orcl > 指导中心 > SQL 优化概要 ...
- CSV解析
NSString *path = [[NSBundle mainBundle] pathForResource: @"type" ofType:@"csv"]; ...
- 开启apahce的mod_speling.so模块,让使用apahce http服务器不再有大小写烦恼
今天把服务器重新安装系统,做apache调优前,优化下apache对网络地址大小写不区分的支持.记录如下: 编译mod_speling.so模块去除Apache-url大小写字母敏感的配置 1. 进入 ...
- codeforces 235 B lets play osu!
cf235B 一道有意思的题.(据说是美少女(伪)计算机科学家出的,hh) 根据题目要求,就是求ni^2的和. 而n^2=n*(n-1)+n; n*(n-1)=C(n,2)*2: 所以∑ai^2=∑a ...
- Calling method 'get' is not valid without an active transaction
在进行使用注解来配置Spring和Hibernate的整合的时候, 遇到了这个问题, 它的意思是说在调用'get'方法的时候,没有活动的事务. 原因分析: Hibernate强制要求在进行数据库操作的 ...
- Spring-02 Java配置实现IOC
Java配置 Spring4推荐使用java配置实现IOC Spring boot也推荐采用java配置实现IOC 在实际项目中,一般采用注解配置业务bean,全局配置使用Java配置. Java配置 ...