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 ...
随机推荐
- Left join 中On和Where的作用范围
SQL语句如下: SELECT * FROM 表1 LEFT JOIN 表2 ON 表1.id = 表2.id AND 表2.Name != 'ff'WHERE 表1.NAME != 'aa' Lef ...
- UI:自定义键盘的实现
自定义我的封装键盘,并在试图控制器里对接 (解决多 输入框问题,把输入框存入到可变数组) @implementation AppDelegate - (BOOL)application:(UIAppl ...
- 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息--3.2 Create创建用户]
3.2 Create创建用户 [HttpPost, Authorize] public async Task<ActionResult> Create( [Bind(Include = & ...
- MFC中OnDraw()和OnPaint()的区别[转]
问题 问题:我在视图画的图象或者文字,当窗口改变后为什么不见了?OnDraw()和OnPaint()两个都是解决上面的问题,有什么不同? OnDraw()和OnPaint()好象兄弟俩,因为它们的工作 ...
- Oracle 建表常用数据类型的详解
创建表时,必须为表的各个列指定数据类型.如果实际的数据与该列的数据类型不相匹配,则数据库会拒绝保存.如为学生指定出生日期为“1980-13-31”. 在Oracle中,常见的数据类型有: 字符串:字符 ...
- Keil MDK AGDI Drivers, ULink, JLink, ST-Link, NuLink, JTAGjet
AGDI Drivers AGDI is an Application Program Interface (API) third-party developers can use to create ...
- SpinLock 自旋锁, CAS操作(Compare & Set) ABA Problem
SpinLock 自旋锁 spinlock 用于CPU同步, 它的实现是基于CPU锁定数据总线的指令. 当某个CPU锁住数据总线后, 它读一个内存单元(spinlock_t)来判断这个spinlock ...
- Freescale OSBDM JM60仿真器
OSBDM-JM60 - 9S08JM60 Based OSBDM — It includes interfaces and firmware applied to all the targets s ...
- CSS规则整理
一. 善用css缩写规则 /*注意上.右.下.左的书写顺序*/1. 关于边距(4边):1px 2px 3px 4px (上.右.下.左)1px 2px 3px (省略的左等于右)1px 2px (省略 ...
- Celery学习笔记
转载请注明出处:点我 我的第一篇博客!嘿嘿! 在公司实习,接触到的第一个项目就用到了Celery,之前是完全没有接触过Celery这玩意,然后花了点时间仔细的研究了下怎么用.在学习过程中也遇到了些问题 ...