Message 模拟题

Message
Asia - Taipei - 2008/2009
PDF   Submit   Ranking

 

 

Astronomers have been looking for living beings in the outer planets. Recently the Hobble telescope has picked up binary (black and white) images from the Zkrets planet (1 light-years away). Each image contains exactly one symbol. Together the sequence of symbols (images) represents a message for aliens from other planets. A team of deciphering experts has found some decoding scheme that assigns an English alphabet to each symbol. The decoding process would be easy if each received image were in perfect condition. Unfortunately, due to long distance transmission, the images received usually contain some noise, meaning that some white pixels are turned into black pixels and vise versa. Furthermore, due to self-rotation of the Hobble telescope, the images, when captured, might be rotated 0, 90, 180 or 270 degrees. To expedite the message decoding process, please write a program to decode the received sequence of images automatically.

 


Technical Specification

The number of images received is n, where 1n100 . The size of the image is always scaled to 10×10 . Within the image, `1' represents a black pixel (part of the symbol) and `0' represents a white pixel (not part of the symbol).
Each received image may contain at most 20% noise. This means that at most 20 pixels may have their gray levels changed (from black to white or from white to black) during transmission. Each image is rotated 0, 90, 180 or 270 degrees in clockwise direction.
The number of matching symbols and English Alphabets is m , where 1m52 . The matching English Alphabets can be either upper-case or lower-case letters.

Input 
There are two parts of input, one follows the other. For the first part, it contains the matching English alphabets and image symbols. Thus, the first line contains an integer m , the number of matching alphabets and symbols. The next 11m lines define the m sets of matching alphabets and symbols. The first line of each set contains a single unique English letter. The next 10 lines give the matching symbol in a perfect (no noise, no rotation) 10×10 image of 0's and 1's. For the second part, it contains a sequence of received images. The first line contains an integer n , the number of 10×10 images received. The next 10n lines present the n images received. Every 10 lines define one image. Each line contains exactly 10 consecutive 0's and 1's.


Output 
Please print out the corresponding English letters of the received input images in sequence, all on one line. If more than one match is possible for a given input image, output the matching one with the least number of noise pixels. If there is still a tie, output the one that appears first in the input sequence of English alphabets.

 


Explanations for the Sample:


There are 2 deciphered matching codes.
The first is coded as letter a. The corresponding image is giving in 10 rows of consecutive 0's and 1's.

The second image is coded as letter X. The corresponding image is giving in 10 rows of consecutive 0's and 1's.


There are 3 received images waiting to be decoded.
The first received image has 10 rows of consecutive 0's and 1's. It matches with the corresponding image of the coded symbol 'X' perfectly without any noise. The image is either not rotated or perhaps rotated by 180 degrees.

The second image has also 10 rows of consecutive 0's and 1's. It also matches with the corresponding image of the coded symbol 'X' perfectly without any noise. However, the image is either rotated by 90 or 270 degrees.

The third image has also 10 rows of consecutive 0's and 1's. It contains 12 noise pixels. The image is also rotated by 90 degrees. It matches with the corresponding image of the coded symbol 'a'.


Sample Input 

2
a
0000000000
0111111110
0111110011
0111111100
0000110000
0000110000
0001111100
0011111110
0000000000
0000000000
X
0110000110
0110000110
0011001100
0011001100
0001111000
0001111000
0011001100
0011001100
0110000110
0110000110
3
0110000110
0110000110
0011001100
0011001100
0001111000
0001111000
0011001100
0011001100
0110000110
0110000110
0000000000
1100000011
1111001111
0011111100
0000110000
0000110000
0011111100
1111001111
1100000011
0000000000
0000000000
0000001110
1110001110
0000110001
0011111110
0011111110
0011001010
0011001010
0010000110
0000000010


Sample Output 

XXa

 

#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
struct node
{
    char ch;
    string code[11];
    int v;
};
int dif(node a,node b)
{
    int cnt=0;
    for(int i=0;i<10;i++) for(int j=0;j<10;j++) cnt+=(a.code[i][j]!=b.code[i][j]);
    return cnt;
}   
int Min(int a,int b,int c,int d)
{
    a=a<b?a:b;c=c<d?c:d;
    return a<c?a:c;
}    
int main()
{
    int n,m;
    while(scanf("%d",&n)==1)
    {
        node c[110];
        for(int i=0;i<n;i++)
        {
            cin>>c[i].ch;
            for(int j=0;j<10;j++) cin>>c[i].code[j];
        }
        string ans;
        cin>>m;
        while(m--)
        {
            node temp[4];
            for(int i=0;i<10;i++) cin>>temp[0].code[i];
            for(int i=1;i<4;i++)
            {
                for(int j=0,g=0;j<10;j++,g++)
                {
                    for(int k=0,h=9;k<10;k++,h--)
                    {
                        //cout<<j<<"..."<<k<<"..."<<h<<"..."<<g<<endl;
                        temp[i].code[j]+=temp[i-1].code[h][g];
                    }
                }
            }
          /*  for(int i=1;i<4;i++)
            {
                cout<<"................."<<endl;
                for(int j=0;j<10;j++) cout<<temp[i].code[j]<<endl;
            }  */ 
            //cout<<"ok"<<endl;
            int p,cnt=(1<<31)-1;
            for(int i=0;i<n;i++)
            {
                int t=Min(dif(temp[0],c[i]),dif(temp[1],c[i]),dif(temp[2],c[i]),dif(temp[3],c[i]));     
                if(t<=20&&t<cnt)
                {
                    t=cnt;p=i;
                }
            }
            ans+=c[p].ch;
        }
        cout<<ans<<endl;
    }
    return 0;
}                   
               

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值