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 ...
随机推荐
- 优化checkbox和radio,类似Bootstrap中的iCheck
checkbox和radio浏览器默认的已经满足不了大众的审美需求,更不用说浏览器之间的差异化,取而代之,优化checkbox和radio的方法也随之诞生了. html结构:单选框为例,简单说明: 其 ...
- 当类库项目中无法使用Application.StartupPath
通常我们WinForm编程时,要获取程序当前运行的文件夹路径会用Application.StartupPath ,但是Application.StartupPath在编写类库项目时却无法使用,因为我们 ...
- strlen() 和 sizeof() 在字符串中的使用
#include <string.h> int _tmain(int argc, _TCHAR* argv[]) { char *pMyChar = "I like coding ...
- OpenGL光照测试
OpenGL光照测试 花了大概半个月,研究了OpenGL的光照.请注意是固定管线渲染的光照,如果使用着色器的高手们请飘过.这个程序是通过光照对模型的照射,来研究OpenGL光照的性质.以后可以通过这个 ...
- android学习记录(十三)Task 和 Activity 回退栈操作。
首先说一下Task是一个什么概念吧:Task是一个包括activity的列表.没 错.简单的说就是依照启动的先后来排队的一个队列.Back Stack.就是回退栈的意思:那么有什么用?Back Sta ...
- jQuery.FlexiGrid使用总结
经过对FlexiGrid的大量使用,及时不时琢磨下其代码,对她的脾性有了一定的了解,是该做总结的时候了. 一.FlexiGrid下载 1.原版代码 最近Paulo P. Marinas对FlexiGr ...
- Codeforces Gym 100531I Instruction 构造
Problem I. Instruction 题目连接: http://codeforces.com/gym/100531/attachments Description Ingrid is a he ...
- Codeforces Educational Codeforces Round 5 C. The Labyrinth 带权并查集
C. The Labyrinth 题目连接: http://www.codeforces.com/contest/616/problem/C Description You are given a r ...
- Codeforces Round #215 (Div. 2) B. Sereja and Suffixes map
B. Sereja and Suffixes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset ...
- 车牌识别--S5PV210測试
cortex-A8(S5PV210) Linux-3.9.7 arm-linux-gcc 4.5.1(FriendlyARM) 根文件系统:NFS 软浮点执行结果: [liujia@210]#./so ...