The 8th(2013) ACM Programming Contest of HUST Problem Set
Little Mine is a naughty boy. He was once an excellent student and has won a great many prizes since the primary school. However, he’s also addicted to video games. After he goes to college, when it comes to physics, his performance turns out the opposite way.
His teacher Mr. Wang is a nice person. When hearing about Littlemine’s story, he decided to offer him an “opportunity”. If he could solve the difficult problem, he wouldn’t have to hand in his homework for the whole semester(ACTUALLY Mr.Wang WANTS HIM TO FIND A WAY BACK TO BE A GOOD STUDENT). Here is the problem:
This is a map consisting of multiple constellations(A constellation means a union of connected stars, each one of them has at least one star in its eight adjacent positions, and one constellation cannot be a part of another bigger constellation). Two constellations are similar if and only if they have same amount of stars and exact the same shape, ignoring the difference of their directions.
Here we use a n*m (0<=n,m<=100) matrix consisting of ones and zeros to denote the map. One means there’s a star in its position (the total number of stars won’t exceed 500), while zero means nothing. Given such a matrix, you need to use a lower-case letter to denote all the constellations. Similar constellations must be marked with the same letter. There are at most 26 different constellations and each one has at most 160 stars. Check the example below to learn more details.
But Little Mine doesn’t buy it, he makes up his mind to put things “right” once and for all. So he asks you for help. Will you help him?