• 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

     

    *


    作者:loverszhaokai
    出处:http://www.cnblogs.com/lovers
    本文采用知识共享署名-非商业性使用-相同方式共享 2.5 中国大陆许可协议进行许可,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。

  • 相关阅读:
    WPF进阶技巧和实战03-控件(3-文本控件及列表控件)
    WPF进阶技巧和实战08-依赖属性与绑定03
    WPF进阶技巧和实战08-依赖属性与绑定02
    WPF进阶技巧和实战08-依赖属性与绑定01
    WPF进阶技巧和实战07--自定义元素02
    WPF进阶技巧和实战07--自定义元素01
    Codeforces Round #730 Div. 2
    Codeforces Round #701 Div. 2
    Codeforces Round #700 Div. 2
    Codeforces Round #699 Div. 2
  • 原文地址:https://www.cnblogs.com/lovers/p/3669942.html
Copyright © 2020-2023  润新知