#P2749. [IOI 1998 / USACO5.1] 夜空繁星 Starry Night

    ID: 1760 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>USACO枚举,暴力广度优先搜索,BFS

[IOI 1998 / USACO5.1] 夜空繁星 Starry Night

Description

The night sky can be represented as a sky map, which is a 2D matrix of characters 0 and 1. A character 1 indicates there is a star at that position; a character 0 indicates the position is empty.

Given a sky map, use the same lowercase English letter to mark all similar clusters.

Similar clusters must be marked with the same letter, and different clusters must be marked with different letters. To mark a cluster, replace each 1 corresponding to a star in that cluster with the appropriate lowercase letter.

Input Format

The first two lines contain the width WW and the height HH of the sky map, respectively. The sky map then follows in the next HH lines, each containing WW characters.

Output Format

Output the sky map after marking the clusters (in the same format as the input, except that clusters are marked).

For the same input, there may be many valid markings; in that case, output the lexicographically smallest marking.

23
15
10001000000000010000000
01111100011111000101101
01000000010001000111111
00000000010101000101111
00000111010001000000000
00001001011111000000000
10000001000000000000000
00101000000111110010000
00001000000100010011111
00000001110101010100010
00000100110100010000000
00010001110111110000000
00100001110000000100000
00001000100001000100101
00000001110001000111000
a000a0000000000b0000000
0aaaaa000ccccc000d0dd0d
0a0000000c000c000dddddd
000000000c0b0c000d0dddd
00000eee0c000c000000000
0000e00e0ccccc000000000
b000000e000000000000000
00b0f000000ccccc00a0000
0000f000000c000c00aaaaa
0000000ddd0c0b0c0a000a0
00000b00dd0c000c0000000
000g000ddd0ccccc0000000
00g0000ddd0000000e00000
0000b000d0000f000e00e0b
0000000ddd000f000eee000

Hint

Sample Explanation

In this case, the sky map is a 2D matrix with length 2323 and width 1515.

The input corresponds to the following image of the matrix.

The output corresponds to the following view of the night sky.

Constraints

  • 00 \le the length and width of the sky map 100\le 100.
  • 00 \le the number of clusters 500\le 500.
  • 00 \le the number of dissimilar clusters 26\le 26.
  • 11 \le the number of stars in each cluster 160\le 160.

Translated by ChatGPT 5