Google code jam Qualification Round 2014
题目链接:https://code.google.com/codejam/contest/dashboard?c=2974486#s=p2
Download:source code
#Define LEFT = R*C – M
ok.
C |
* |
* |
* |
* |
* |
* |
* |
* |
ok.
LEFT = {1}
C |
* |
* |
C |
* |
* |
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) |
* |
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 |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
. |
Each i from 8 to R*C can be
i = 8
C |
1 |
1 |
* |
* |
* |
* |
1 |
1 |
1 |
* |
* |
* |
* |
1 |
1 |
* |
* |
* |
* |
* |
* |
* |
* |
* |
* |
* |
* |
if we want to goto i(8 < i <= R*C)
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 |
* |
* |
* |
* |
* |
* |
* |
* |
* |
* |
* |
* |
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 |
* |
* |
* |
* |
* |
* |
* |
* |
* |
* |
* |
* |
C |
0 |
1 |
* |
* |
* |
* |
0 |
1 |
1 |
* |
* |
* |
* |
0 |
1 |
* |
* |
* |
* |
* |
0 |
1 |
* |
* |
* |
* |
* |
0 |
1 |
* |
* |
* |
* |
* |
0 |
1 |
* |
* |
* |
* |
* |
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 |
* |
* |
* |
* |
* |
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 |
* |
* |
* |
* |
* |
C |
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
* |
* |
* |
* |
* |
0 |
1 |
* |
* |
* |
* |
* |
0 |
1 |
* |
* |
* |
* |
* |
0 |
1 |
* |
* |
* |
* |
* |
3 <= column <= C;
Each column from the third to the last left (R-2) positions.
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 |
* |
* |
* |
* |
* |
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 |
* |
* |
* |
* |
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 |
* |