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 ...
随机推荐
- IAR USING PRE- AND POST-BUILD ACTIONS
Using pre-build actions for time stamping If necessary, you can specify pre-build and post-build act ...
- PL/pgSQL学习笔记之四
http://www.postgresql.org/docs/9.1/static/plpgsql-structure.html 39.2. PL/pgSQL 的结构 PL/pgSQL是一种块式结构的 ...
- Linux Kconfig及Makefile学习
内核源码树的目录下都有两个文档Kconfig (2.4版本是Config.in)和Makefile.分布到各目录的Kconfig构成了一个分布式的内核配置数据库,每个Kconfig分别描述了所属目录源 ...
- jQuery hover事件鼠标滑过图片半透明标题文字滑动显示隐藏
1.效果及功能说明 hover事件制作产品图片鼠标滑过图片半透明,标题文字从左到右滑动动画移动显示隐藏 2.实现原理 首先把效果都隐藏,然后定义一个伪类来触发所有的效果,接下来当触发伪类后会有一个遍历 ...
- iframe式ajax调用示例
1.新建 a.html <!doctype html> <html> <head> <meta charset='utf-8'> <title&g ...
- C#操作XML的完整例子——XmlDocument篇
这是一个用c#控制台程序下, 用XmlDocument 进行XML操作的的例子,包含了查询.增加.修改.删除.保存的基本操作.较完整的描述了一个XML的整个操作流程.适合刚入门.net XML操作的 ...
- HTML 转义符
特殊字符 字符 十进制 转义字符 “ " " & & & < < < > > > 不断开空格(non-breaking ...
- jQuery 效果 - animate() 方法
http://www.w3school.com.cn/jquery/effect_animate.asp 实例 改变 "div" 元素的高度: $(".btn1" ...
- asp.net 获取url
string url = Request.Url.ToString(); this.ImageLogo.ImageUrl = "http://" + Request.Url.Aut ...
- 在Android上使用ZXing识别条形码/二维码
越来越多的手机具备自动对焦的拍摄功能,这也意味着这些手机可以具备条码扫描的功能.......手机具备条码扫描的功能,可以优化购物流程,快速存储电子名片(二维码)等. 本文使用ZXing 1.6实现条码 ...