HDU 1218 Blurred Vision

Blurred Vision

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


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 2 00 00 END START 2 9 012345678 012345678 END START 4 4 4440 4400 4000 0000 END START 9 9 900000009 090000090 009000900 000909000 000090000 000909000 009000900 090000090 900000009 END ENDOFINPUT
 

Sample Output
  
  
0 01234567 431 310 100 42000024 24200242 02422420 00244200 00244200 02422420 24200242 42000024
 

Source
 

Recommend
Eddy

题意:把m*n的矩阵压缩成(m-1)*(n-1)的矩阵,根据题意的方法是每一个数加上它左边的一个数加下面的一个数再加下面右边的一个数(最后行最后列不不用)然后除以4,就成新矩阵的一个数

代码:

#include<stdio.h>
#include<string.h>

int a[11][11];
int b[11][11];        

int main()
{
     char str[12];
     int R,C;
     while(scanf("%s",str))
     {
         if(strcmp(str,"ENDOFINPUT")==0)
             break;
         scanf("%d%d",&R,&C);
         int i=0,j=0;
         while(scanf("%s",str),strcmp(str,"END"))
         {
             for(j=0;j<C;j++)
                 a[i][j]=str[j]-'0';
             i++;
         }
           for(i=0;i<R-1;i++)
               for(j=0;j<C-1;j++)
                   b[i][j]=(a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1])/4;
           for(i=0;i<R-1;i++)
           {
               for(j=0;j<C-1;j++)
                   printf("%d",b[i][j]);
               printf("\n");
           }
     }
     return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值