Problem:Minesweeper Master

Google code jam Qualification Round 2014

 题目链接:https://code.google.com/codejam/contest/dashboard?c=2974486#s=p2

Download:source code

word版文档下载

 

#Define LEFT = R*C – M

  1. M==R*C-1

ok.

C

*

*

*

*

*

*

*

*

  1. M<R*C-1

    1. R==1 or C == 1

ok.

LEFT = {1}

C

*

*

 

C

*

*

  1. R==2 or C == 2

It is ok when the LEFT are even, and so does C==2.

LEFT = {1,4,6,8,..2n} n=max(R,C);

 

C

.

*

.

.

*

 

C

.

*

.

*(wrong)

*

  1. R>=3 && C >= 3

LEFT = {1,2,3,4,5,6,7,8,9,10,…,i,…,R*C};

LEFT = {1,4, 6,8,9,10,…,i,…,R*C}; 8<=i<=R*C; //Proved at 2.3.1

1

4

C

.

*

*

.

.

*

*

*

*

*

*

6

C

.

.

*

.

.

.

*

*

*

*

*

8

C

.

.

.

.

.

.

.

*

*

*

*

9

C

.

.

*

.

.

.

*

.

.

.

*

10

C

.

.

.

.

.

.

.

.

.

*

*

11

C

.

.

.

.

.

.

.

.

.

.

*

12

C

.

.

.

.

.

.

.

.

.

.

.

  1. Prove that i is from 8 to R*C one by one

Each i from 8 to R*C can be

  1. firstly

i = 8

C

1

1

*

*

*

*

1

1

1

*

*

*

*

1

1

*

*

*

*

*

*

*

*

*

*

*

*

  1. secondly

if we want to goto i(8 < i <= R*C)

  1. 8 < i <= 8 + 2 * (R-2)
    1. 0 == i % 2

Only set the first and second columns is enough.

Add two each time.

C

0

1

*

*

*

*

0

0

1

*

*

*

*

0

1

*

*

*

*

*

0

1

*

*

*

*

*

1

1

*

*

*

*

*

*

*

*

*

*

*

*

  1. 0 != i % 2

Set the first and second columns to (i-1).

And set [2][2]

C

0

1

*

*

*

*

0

0

1

*

*

*

*

0

1

1

*

*

*

*

0

1

*

*

*

*

*

1

1

*

*

*

*

*

*

*

*

*

*

*

*

  1. 8 + 2 * (R-2) < i <= 2 * (R+C-2)
    1. Set full of the first and second columns

C

0

1

*

*

*

*

0

1

1

*

*

*

*

0

1

*

*

*

*

*

0

1

*

*

*

*

*

0

1

*

*

*

*

*

0

1

*

*

*

*

*

  1. 0 == i % 2

Only set the first and second rows is enough.

Add two each time.

C

0

0

0

1

*

*

0

1

1

1

1

*

*

0

1

*

*

*

*

*

0

1

*

*

*

*

*

0

1

*

*

*

*

*

0

1

*

*

*

*

*

 

  1. 0 != i % 2

Set the first and second columns to (i-1).

And set [2][2]

C

0

0

0

1

*

*

0

0

1

1

1

*

*

0

1

1

*

*

*

*

0

1

*

*

*

*

*

0

1

*

*

*

*

*

0

1

*

*

*

*

*

  1. 2 * (R+C-2) < i <= R*C

C

0

0

0

0

0

0

0

1

1

1

1

1

1

0

1

*

*

*

*

*

0

1

*

*

*

*

*

0

1

*

*

*

*

*

0

1

*

*

*

*

*

  1. 2 * (R+C-2) < i <= 2*(R+C-2)+(R-2)*(column-2)

3 <= column <= C;

Each column from the third to the last left (R-2) positions.

  1. 2 * (R+C-2) < i <= 2*(R+C-2)+(R-2)*(3-2)

Set the third column (i-2*(R+C-2)) from [2][2] to [R-1][2]

   

3

       

C

0

0

0

0

0

0

0

0

1

1

1

1

1

0

0

1

*

*

*

*

0

1

1

*

*

*

*

0

1

*

*

*

*

*

0

1

*

*

*

*

*

  1. 2 * (R+C-2) < i <= 2*(R+C-2)+(R-2)*(4-2)

Set full of the third column.

Set the fourth column (i-2*(R+C-2) – (R-2)) from [2][3] to [R-1][3]

   

3

4

     

C

0

0

0

0

0

0

0

0

0

1

1

1

1

0

0

0

1

*

*

*

0

0

0

1

*

*

*

0

0

1

1

*

*

*

0

0

1

*

*

*

*

  1. 2 * (R+C-2) < i <= 2*(R+C-2)+(R-2)*(k-2)

Set full of the third to (k-1) columns.

Set the k column (i-2*(R+C-2) – (k-3)(R-2)) from [2][k-1] to [R-1][k-1]

   

3

 

k-1

k

 

C

0

0

0

0

0

0

0

0

0

0

0

1

1

0

0

0

0

0

1

*

0

0

0

0

1

1

*

0

0

0

0

1

 

*

0

0

0

0

1

 

*

你可能感兴趣的:(master)