Let's first agree: When and only when two cells share at least one vertex, they are called "adjacent"; the cell in the i-th column and j-th row of the grid is denoted as (i,j).
(1) Let mi(i=1,2,⋯,3n2+4n) represent the number of mine cells adjacent to the number cell Mi, and let lj(j=1,2,⋯,n2+1) represent the number of number cells adjacent to the mine cell Lj. Since the adjacency relationship is mutual, we have
∑mi=∑lj.
We only need to find the maximum value of ∑li.
For n=1, by trial, we get ∑lj⩽11.
When n⩾2, let there be B mine cells on the boundary (excluding the four corners), J mine cells at the four corners, and S pairs of adjacent mine cells. A mine cell not on the boundary or corners can be adjacent to at most 8 number cells, a mine cell on the boundary can be adjacent to at most 5 number cells, and a mine cell at the corner can be adjacent to at most 3 number cells. Apart from the positional factors, each pair of adjacent mine cells (Lk,Lj) will cause lk and lj to each decrease by 1, thus reducing ∑li by 2. Therefore,
∑lj=8(n2+1)−(8−5)B−(8−3)J−2S
=8(n2+1)−3B−5J−2S.
Clearly, ∑lj=8(n2+1)−1.
First, we prove:
∑lj=8(n2+1) and ∑lj=8(n2+1)−2,
i.e., (B,J,S)=(0,0,0) and (B,J,S)=(0,0,1).
Proof by contradiction.
Assume (B,J,S)=(0,0,0) or (0,0,1).
We provide two ways to partition the grid.
Partition 1: For any r,S∈{0,1,⋯,n},
cells (2r,2s)、(2r+1,2s)、(2r,2s+1)、(2r+1,2s+1) are grouped into one region.
Partition 2: For any r,S∈{0,1,⋯,n}, cells (2r+1,2s+1)、(2r+1,2s+2)、(2r+2,2s+1)、(2r+2,2s+2) are grouped into one region (a region is considered to exist only if it contains at least one meaningful cell or a cell that has not been removed).
Since B=J=0, we can remove all corner cells, leaving n2 regions. Because n⩾2, there exists at least one region containing 2 cells. Since the total number of mine cells is n2+1, by the pigeonhole principle, there must be a region containing at least two mine cells, i.e., a pair of adjacent mine cells, so S=0.
Similarly, there is a pair of adjacent mine cells in Partition 2. Note that in Partition 1, two cells in the same region are in different regions in Partition 2. Thus, these two pairs of adjacent mine cells are different. Therefore, S=1. This contradicts both assumptions, so the assumptions are false, i.e., (B,J,S)=(0,0,0) and (B,J,S)=(0,0,1).
Next, we prove: ∑lj=8(n2+1)−3, i.e.,
(B,J,S)=(1,0,0).
Proof by contradiction.
Assume (B,J,S)=(1,0,0). Suppose the mine cell on the boundary is at (k,1). After removing all corner cells and using Partition 1, we form n2 regions. Since S=0, each region must contain exactly one mine cell; and to ensure no mine cell is adjacent to (k,1), (k−1,2)、(k,2)、(k+1,2) must not be mine cells. But these three cells already contain one region, which is a contradiction. Therefore, the assumption is false, i.e., (B,J,S)=(1,0,0).
Thus, ∑li⩽8(n2+1)−4, with equality when (B,J,S)=(0,0,2).
In fact, when all cells in even rows and even columns are mine cells, and cell (3,2) is a mine cell, the maximum value can be achieved (at this time, the pairs of adjacent mine cells are only (2,2) and (3,2) and (4,2).
In summary, for n=1, the maximum value is 11; for n⩾2, the maximum value is 8n2+4.
(2) If the smallest positive integer q such that there exists an n×n grid with q mine cells and no number cell filled with 0 is qmin , then kmax =qmin −1.
Note that a grid has no 0 if and only if each cell satisfies: it is a mine cell or it is adjacent to at least one mine cell.
Let S={(i,j)∣i=j≡1(mod3)}.
Then ∣S∣=[3n+2]2([x] denotes the greatest integer not exceeding the real number x).
For any (i,j)∈S, let the set of (i,j) and all cells adjacent to it be S(i,j). It is easy to see that the intersection of any two S(i,j) is empty. Since any two cells in S are not adjacent and cannot be adjacent to the same mine cell, and (i,j) must satisfy: it is a mine cell or it is adjacent to at least one mine cell, each S(i,j) must contain at least one mine cell, i.e., q⩾∣S∣.
To make q attain this minimum value, we only need to let each (i,j) satisfying i≡j≡1(mod3) be a mine cell when n=1(mod3); and let each (i,j) satisfying i≡j=2(mod3) be a mine cell when n≡0(mod3) or n≡2(mod3). It is easy to verify that in this case q=∣S∣ and the grid has no number 0. Thus, qmin =[3n+2]2.
Therefore, kmax =qmin −1=[3n+2]2−1.