Problem:Minesweeper Master
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
M==R*C-1
ok.
|
C |
* |
* |
|
* |
* |
* |
|
* |
* |
* |
M<R*C-1
R==1 or C == 1
ok.
LEFT = {1}
|
C |
* |
* |
|
C |
|
* |
|
* |
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) |
* |
R>=3 && C >= 3
,,4,,6,,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 |
. |
. |
. |
|
. |
. |
. |
. |
|
. |
. |
. |
. |
Prove that i is from 8 to R*C one by one
Each i from 8 to R*C can be
firstly
i = 8
|
C |
1 |
1 |
* |
* |
* |
* |
|
1 |
1 |
1 |
* |
* |
* |
* |
|
1 |
1 |
* |
* |
* |
* |
* |
|
* |
* |
* |
* |
* |
* |
* |
secondly
if we want to goto i(8 < i <= R*C)
8 < i <= 8 + 2 * (R-2)
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 |
* |
* |
* |
* |
* |
|
* |
* |
* |
* |
* |
* |
* |
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 |
* |
* |
* |
* |
* |
|
* |
* |
* |
* |
* |
* |
* |
8 + 2 * (R-2) < i <= 2 * (R+C-2)
Set full of the first and second columns
|
C |
0 |
1 |
* |
* |
* |
* |
|
0 |
1 |
1 |
* |
* |
* |
* |
|
0 |
1 |
* |
* |
* |
* |
* |
|
0 |
1 |
* |
* |
* |
* |
* |
|
0 |
1 |
* |
* |
* |
* |
* |
|
0 |
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 |
* |
* |
* |
* |
* |
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 |
* |
* |
* |
* |
* |
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 |
* |
* |
* |
* |
* |
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.
- 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 |
* |
* |
* |
* |
* |
- 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 |
* |
* |
* |
* |
- 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 |
* |
Problem:Minesweeper Master的更多相关文章
- Google Code Jam 2014 资格赛:Problem C. Minesweeper Master
Problem Minesweeper is a computer game that became popular in the 1980s, and is still included in so ...
- The 2015 China Collegiate Programming Contest A. Secrete Master Plan hdu5540
Secrete Master Plan Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Othe ...
- hdu 5540 Secrete Master Plan(水)
Problem Description Master Mind KongMing gave Fei Zhang a secrete master plan stashed × matrix, but ...
- ACM Secrete Master Plan
Problem Description Master Mind KongMing gave Fei Zhang a secrete master plan stashed in a pocket. T ...
- HDU-5540 Secrete Master Plan
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submission( ...
- Master of Subgraph
Problem E. Master of SubgraphYou are given a tree with n nodes. The weight of the i-th node is wi. G ...
- 2017ccpc 杭州Master of Sequence
Problem K. Master of SequenceTherearetwosequencesa1,a2,··· ,an, b1,b2,··· ,bn. LetS(t) =∑n i=1⌊t−bi ...
- Google Code Jam 2014 Qualification 题解
拿下 ABD, 顺利晋级, 预赛的时候C没有仔细想,推荐C题,一个非常不错的构造题目! A Magic Trick 简单的题目来取得集合的交并 1: #include <iostream> ...
- HDU5477(模拟)
A Sweet Journey Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
随机推荐
- 使用XML与远程服务器进行交互
最近在做的一个项目其中的一部分是与远程服务器进行交互,确定身份验证的合法性,于是编写了SendRequest方法 此方法发送给远程服务器XML请求,服务器经过处理后,返回XML回应,由此方法接收到后进 ...
- Minus-C 一个最小化的C语言规范
资深C++程序员都不会对C++编程规范太陌生,C++实在太复杂,以至于所有项目都需要裁剪一个子集共项目组内使用.经过在家休息这一小段时间,我发现其实C语言更需要一个相同的规范,这就是本文的目标,最大可 ...
- SPSS二次开发
在以前关于SPSS二次开发文章中留下过自己联系方式,差不多一年的时间,零零散散的和我取得联系的人也有几十位,看来对于SPSS二次开发的需求不少. Web SPSS系统是利用SPSS二次开发技术,使用户 ...
- 在WPF程序中使用摄像头兼谈如何使用AForge.NET控件(转)
前言: AForge.NET 是用C#写的一个关于计算机视觉和人工智能领域的框架,它包括图像处理.神经网络.遗传算法和机器学习等.在C#程序中使用摄像头,我习惯性使用AForge.NET提供的类库.本 ...
- [效果]JS折叠菜单-使用方法 (Moo.Fx)
(从已经死了一次又一次终于挂掉的百度空间人工抢救出来的,发表日期2014-06-24) 用法: 1.添加JS库 CODE:<script src="prototype.lite.js& ...
- java画图输出到磁盘
直奔主题,实战例子如下 package com.yuanmeng.jase; import java.awt.Color; import java.awt.Font; import java.awt. ...
- TextView 实现复制文本功能
Android api 11 以后可以直接设置 android:textIsSelectable="true" <TextView android:layout_width= ...
- Hadoop on Mac with IntelliJ IDEA - 10 陆喜恒. Hadoop实战(第2版)6.4.1(Shuffle和排序)Map端 内容整理
下午对着源码看陆喜恒. Hadoop实战(第2版)6.4.1 (Shuffle和排序)Map端,发现与Hadoop 1.2.1的源码有些出入.下面作个简单的记录,方便起见,引用自书本的语句都用斜体表 ...
- C语言中结构体 自引用 和 相互引用
http://blog.163.com/modingfa_002/blog/static/11092546620133193264579 结构体的自引用(self reference),就是在结构体内 ...
- PostgreSQL的AnynonArray的例子
程序: CREATE OR REPLACE FUNCTION kappend(anynonarray, anyelement) RETURNS text AS $$ ; $$ LANGUAGE SQL ...