← 返回 uber 的题目列表Generate a Random Minesweeper Grid with N Mines
类型:online_judge
Implement a function to generate an initial Minesweeper board. Given R rows, C columns, and N mines, generate an R x C grid.
Requirements:
Randomly place N mines '*' on distinct cells
Fill all other cells with '0'..'8' indicating the number of mines in its 8-neighborhood
No duplicate mine positions
You may use a PRNG (e.g., random.randint).
Input
R C N
Output
Print R lines, each with C characters (no spaces), consisting of '*' or '0'..'8'
Constraints
1 <= R, C <= 2000
0 <= N <= R*C
Aim for near O(R*C + N) time and minimal extra space
Notes on tests
Random outputs are inherently non-deterministic; tests below validate edge cases and correctness rather than exact mine positions.
Example
Input
1 1 0
Output
0