Algorithm 版 (精华区)
发信人: Lerry (想不开·撞树), 信区: Algorithm
标 题: Starry Night
发信站: 哈工大紫丁香 (2002年03月29日13:57:54 星期五), 站内信件
Starry Night
High up in the night sky, the shining stars appear in clusters of various sh
apes. A cluster is a non-empty group of neighbouring stars, adjacent in hori
zontal, vertical or diagonal direction. A cluster cannot be a part of a larg
er cluster.
Clusters may be similar. Two clusters are similar if they have the same shap
e and number of stars, irrespective of their orientation. In general, the nu
mber of possible orientations for a cluster is eight, as Figure 1 exemplifie
s.
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.
Task
Given a sky map, mark all the clusters with lower case letters. Similar clus
ters must be marked with the same letter; non-similar clusters must be marke
d with different letters.
You mark a cluster with a lower case letter by replacing every 1 in the clus
ter by that lower case letter.
Input Data
In file STARRY.IN 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, o
f W characters each.
Sample Input
23
15
10001000000000010000000
01111100011111000101101
01000000010001000111111
00000000010101000101111
00000111010001000000000
00001001011111000000000
10000001000000000000000
00101000000111110010000
00001000000100010011111
00000001110101010100010
00000100110100010000000
00010001110111110000000
00100001110000000100000
00001000100001000100101
00000001110001000111000
In this case, the sky map has width 23 and height 15. Just to make it cleare
r, notice that this input file corresponds to the following picture of the s
ky.
Figure 2. Picture of the sky
Output Data
The file STARRY.OUT contains the same map as STARRY.IN, except that the clus
ters are marked as described in Task.
Sample Output
a000a0000000000b0000000
0aaaaa000ccccc000d0dd0d
0a0000000c000c000dddddd
000000000c0b0c000d0dddd
00000eee0c000c000000000
0000e00e0ccccc000000000
b000000e000000000000000
00b0f000000ccccc00a0000
0000f000000c000c00aaaaa
0000000ddd0c0b0c0a000a0
00000b00dd0c000c0000000
000g000ddd0ccccc0000000
00g0000ddd0000000e00000
0000b000d0000f000e00e0b
0000000ddd000f000eee000
This is one possible result for the sample input above. Notice that this out
put file corresponds to the following picture.
Figure 3. Picture with the clusters marked
Constraints
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
上一页 | 返回目
--
不在乎天长地久,就怕你从来没有!
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 天外飞仙]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.348毫秒