Pro.ID10195 TitleStarry Night Title链接http://10.20.2.8/oj/exercise/problem?problem_id=10195 AC4 Submit7 Ratio57.14% 时间&空间限制描述High up in the night sky, the shining stars appear in clusters of various shapes. A cluster is a non-empty group of neighbouring stars, adjacent in horizontal, vertical or diagonal direction. A cluster cannot be a part of a larger cluster. Clusters may be similar. Two clusters are similar if they have the same shape and number of stars, irrespective of their orientation. In general, the number of possible orientations for a cluster is eight, as Figure 1 exemplifies. Figure 1. Eight similar clusters The night sky is represented by a sky map, which is a two-dimensional matrix of 0's and 1's. A cell contains the digit 1 if it has a star, and the digit 0 otherwise. Given a sky map, mark all the clusters with lower case letters. Similar clusters must be marked with the same letter; non-similar clusters must be marked with different letters. You mark a cluster with a lower case letter by replacing every 1 in the cluster by that lower case letter. 输入Multiple test cases. For each case, The first two lines contain, respectively, the width W and the height H of a sky map. The sky map is given in the following H lines, of W characters each. 0 ≤ W (width of the sky map) ≤ 100 0 ≤ H (height of the sky map) ≤ 100 0 ≤ Number of clusters ≤ 500 0 ≤ Number of non-similar clusters ≤ 26 (a..z) 1 ≤ Number of stars per cluster ≤ 160 输出Description High up in the night sky, the shining stars appear in clusters of various shapes. A cluster is a non-empty group of neighbouring stars, adjacent in horizontal, vertical or diagonal direction. A cluster cannot be a part of a larger cluster. Clusters may be similar. Two clusters are similar if they have the same shape and number of stars, irrespective of their orientation. In general, the number of possible orientations for a cluster is eight, as Figure 1 exemplifies. Figure 1. Eight similar clusters The night sky is represented by a sky map, which is a two-dimensional matrix of 0's and 1's. A cell contains the digit 1 if it has a star, and the digit 0 otherwise. Given a sky map, mark all the clusters with lower case letters. Similar clusters must be marked with the same letter; non-similar clusters must be marked with different letters. You mark a cluster with a lower case letter by replacing every 1 in the cluster by that lower case letter. Input Multiple test cases. For each case, The first two lines contain, respectively, the width W and the height H of a sky map. The sky map is given in the following H lines, of W characters each. 0 ≤ W (width of the sky map) ≤ 100 0 ≤ H (height of the sky map) ≤ 100 0 ≤ Number of clusters ≤ 500 0 ≤ Number of non-similar clusters ≤ 26 (a..z) 1 ≤ Number of stars per cluster ≤ 160 Output For each case, the output contains the same map as the input file, except that the clusters are marked as described in Task. There will generally be more than one way to label the clusters with letters. Your program should choose the labeling such that if the entire output file is read as a string, this string will be minimal in the lexicographical ordering. Output a blank line after each case. Sample Input 23 In this case, the sky map has width 23 and height 15. Just to make it clearer, notice that this input file corresponds to the following picture of the sky.
Sample Output a000a0000000000b0000000 This is one possible result for the sample input above. Notice that this output file corresponds to the following picture.
Source 样例输入23 In this case, the sky map has width 23 and height 15. Just to make it clearer, notice that this input file corresponds to the following picture of the sky.
样例输出a000a0000000000b0000000 This is one possible result for the sample input above. Notice that this output file corresponds to the following picture.
作者 |