UVALive - 4264

Message


Time Limit:                                                        3000MS                       

 

Memory Limit: Unknown

 

64bit IO Format:                            %lld & %llu                       


SubmitStatus


Description





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

  1. 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).     
  2. 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.
  3. The number of matching symbols and English Alphabets is m     , where 1m52





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 11 m 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 10 n 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



//题意:规定给定的每张表可以通过旋转0,90,180,270度得到4个表,如果测试的表中与给的表的对应位置的不同字符的个数小于等于20个(num<=20可以忽略),那么就说这个表示给的表的对应表。输出这个表的名字。



输入包含两部分,先输入一个m,表示有m个表,每组开始先输入一个字符c(c>='a'&&c<='z'||c>='A'&&c<='Z'),表示这个表的名字;



然后再输入一个10*10 的01表,



第二部分是输入一个数n,表示有n组测试数据,对于每组测试数据找出它是由哪个表得来的。



//思路:



对于每个给定的表将他的生成表(另外3个)都存起来,他们的名字是相同的,然后对于每个测试表都与所有表进行匹配,如果符合要求就截止,输出它的名字即可。




#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
char map[110][15][15];
char s[60][15][15];
char ss[4*60][15][15];
char c[60][2];

int main()
{
	int n,m,i,j,k,l;
	while(scanf("%d",&m)!=EOF)
	{
		for(k=0;k<m;k++)
		{
			scanf("%s",c[k]);
			for(i=0;i<10;i++)
			{
				scanf("%s",s[k][i]);
			}
		}
		int kk=0,ii,jj;
		for(k=0;k<m;k++,kk++)
		{
			for(i=0,ii=0;i<10;i++,ii++)
			{
				for(j=0,jj=0;j<10;j++,jj++)
				{
					ss[kk][ii][jj]=s[k][i][j];
				}
			}
			kk++;
			for(j=0,ii=0;j<10;j++,ii++)
			{
				for(i=9,jj=0;i>=0;i--,jj++)
				{
					ss[kk][ii][jj]=s[k][i][j];
				}
			}
			kk++;
			for(i=9,ii=0;i>=0;i--,ii++)
			{
				for(j=9,jj=0;j>=0;j--,jj++)
				{
					ss[kk][ii][jj]=s[k][i][j];
				}
			}
			kk++;
			for(j=9,ii=0;j>=0;j--,ii++)
			{
				for(i=0,jj=0;i<10;i++,jj++)
				{
					ss[kk][ii][jj]=s[k][i][j];
				}
			}		
		}
		scanf("%d",&n);
		for(k=0;k<n;k++)
		{
			for(i=0;i<10;i++)
			{
				scanf("%s",map[k][i]);
			}
		}
		for(k=0;k<n;k++)
		{
			for(l=0;l<kk;l++)
			{
				int cnt=0,flag=0;
				for(i=0;i<10;i++)
				{
					for(j=0;j<10;j++)
					{
						if(map[k][i][j]!=ss[l][i][j])
							cnt++;
					}
				}
				if(cnt<=20)
				{
					printf("%s",c[l/4]);
					break;
				}
			}
		}
		printf("\n");
	}
	return 0;
}