博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2579 Blurred Vision(我的水题之路——四方格平均值)
阅读量:4069 次
发布时间:2019-05-25

本文共 3682 字,大约阅读时间需要 12 分钟。

Blurred Vision
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1449   Accepted: 1053

Description

Aliasing is the stair-step effect achieved when attempting to represent a smooth curve using a finite number of discrete pixels. Of course, all computer displays consist of a finite number of pixels, and many strategies have been devised to smooth the jagged edges with varying degrees of success. 
Boudreaux and Thibodeaux are writing video game rendering software for the next big first-person shooter, and they don't know much about any of the progress made in the field of anti-aliasing. Therefore, they've decided to use a very simplistic (and visually unappealing) method to smooth the ragged edges. Unfortunately, it blurs the entire image, but at least it gets rid of those jaggies! 
Normally, the game displays in m x n pixels, but they perform an extra anti-aliasing step that converts that image into an (m - 1) x (n - 1) image. Nobody will notice a pixel missing from each dimension, and they can calculate the new pixels by averaging squares of 4 pixels from the original image (and rounding down). For example, the images below represent the original image (left) and the anti-aliased image (right) using numbers to represent varying shades of black and white. 
4 4 4 0
4 4 0 0
4 0 0 0
0 0 0 0
4 3 1
3 1 0
1 0 0

Input

Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. 
A single data set has 3 components: 
  1. Start line - A single line: 
    START R C 
    where R and C are integers (2 <= (R,C) <= 9) indicating the number of rows and columns in the input image described by this data set. 
  2. Original Image - A series of R lines, each of which contains C integers from 0 to 9 inclusive. These integers represent the grayscale value of a pixel in the original image and will not be separated by spaces. 
  3. End line - A single line: 
    END
After the last data set, there will be a single line: 
ENDOFINPUT 

Output

The output will be the anti-aliased image, which will be R - 1 rows, each with C - 1 integer pixel values. Each pixel in the output will be generated by averaging (and rounding down) the grayscale pixel values of the corresponding square of four pixels in the Original Image.

Sample Input

START 2 20000ENDSTART 2 9012345678012345678ENDSTART 4 44440440040000000ENDSTART 9 9900000009090000090009000900000909000000090000000909000009000900090000090900000009ENDENDOFINPUT

Sample Output

0012345674313101004200002424200242024224200024420000244200024224202420024242000024

Source

对于一个R*C的矩阵,输出矩阵中每一个2*2的小方格四个值的平均值(向下取整)。如下图:
先将所有元素读入在一个二维数组中,[0,0] ~[n-1, n-1]。
然后从[1,1]~[n-1, n-1],取[i,j]元素和[i-1,j]、[i,j-1]、[i-1,j-1]元素的平均值,输出。
注意点:
1)输入值前有“STRAT”,之后有“END”字符串,需要忽略这些输入。
2)这些数字中间没有空格间隔,需要用字符读入,注意读入之后的'\n'影响下一步读入。
3)取中间值,所以注意边界,不要越界。
代码(1AC):
#include 
#include
#include
int arr[10][10];char sign[3][20] = {"START", "END", "ENDOFINPUT"};int main(void){ int i, j; int r, c; int ave; char tmp[20]; while (scanf("%s", tmp), strcmp(tmp, sign[2])){ memset(arr, 0, sizeof(arr)); scanf("%d%d", &r, &c); getchar(); for (i = 0; i < r; i++){ for (j = 0; j < c; j++){ arr[i][j] = getchar() - '0'; } getchar(); } for (i = 1; i < r; i++){ for (j = 1; j < c; j++){ ave = arr[i][j] + arr[i - 1][j] + arr[i][j - 1] + arr[i - 1][j - 1]; printf("%d", ave / 4); } printf("\n"); } scanf("%s", tmp); getchar(); } return 0;}

转载地址:http://mooji.baihongyu.com/

你可能感兴趣的文章
gdb 调试core dump
查看>>
gdb debug tips
查看>>
linux和windows内存布局验证
查看>>
本地服务方式搭建etcd集群
查看>>
安装k8s Master高可用集群
查看>>
忽略图片透明区域的事件(Flex)
查看>>
Xpath使用方法
查看>>
移动端自动化测试-Mac-IOS-Appium环境搭建
查看>>
Selenium之前世今生
查看>>
Selenium-WebDriverApi接口详解
查看>>
Selenium-ActionChains Api接口详解
查看>>
Selenium-Switch与SelectApi接口详解
查看>>
Selenium-Css Selector使用方法
查看>>
Linux常用统计命令之wc
查看>>
Java.nio
查看>>
PHP那点小事--三元运算符
查看>>
fastcgi_param 详解
查看>>
Linux中的进程
查看>>
学习python(1)——环境与常识
查看>>
学习设计模式(3)——单例模式和类的成员函数中的静态变量的作用域
查看>>