← 返回 uber 的题目列表Minesweeper Board Generation and Rendering
类型:online_judge
Implement a function to generate and print a Minesweeper board.
Given board size m x n and number of mines k (k <= m*n), randomly place k mines on distinct cells. Then output an m x n grid where:
Mine cells are represented by '*'.
Non-mine cells contain the number of mines in the 8 neighboring cells (including diagonals), from 0 to 8.
Requirements:
Mine placement must be random and without duplicates.
Output may be a 2D array or printed row by row.
Constraints
1 <= m, n <= 200
0 <= k <= m*n
Example (illustrative; randomness means output may vary)
Input: m=3, n=4, k=2
Possible output:
* 1 0 0
2 2 1 0
* 1 0 0
Example
Input
3 4 0 0
Output
0 0 0 0
0 0 0 0
0 0 0 0