杭电1218 Blurred Vision

来源:互联网 发布:淘宝自定义内容区代码 编辑:程序博客网 时间:2024/05/14 12:19

Blurred Vision

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 529    Accepted Submission(s): 423


Problem 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:

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. 
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. 
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
South Central USA 2003
 
简单题,意思是给定一个m*n的二维数组,要求输出经过运算的(m-1)*(n-1)新数组,其中,新数组第i行第j列等于原数组第i行第j列为左上角的边长为2正方形之内数字的所有和除以4取整数;
附代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int ans[110][110],i,j,k,l,m,n,help[110][110];char s[1100],c[1100],a[110][110];int main(){while(scanf("%s",s)&&strcmp(s,"ENDOFINPUT")!=0){scanf("%d%d",&m,&n);for(i=0;i<m;i++)scanf("%s",&a[i]);for(i=0;i<m;i++)for(j=0;j<n;j++)help[i][j]=a[i][j]-'0';scanf("%s",c);memset(ans,0,sizeof(ans));int ii,jj;for(i=0;i<m-1;i++)for(j=0;j<n-1;j++){ans[i][j]=help[i][j]+help[i+1][j+1]+help[i+1][j]+help[i][j+1];ans[i][j]/=4;}for(i=0;i<m-1;i++){for(j=0;j<n-1;j++)printf("%d",ans[i][j]);printf("\n");}}}


0 0
原创粉丝点击