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 ...
随机推荐
- How Tomcat Works(三)
上文中描述的简单的服务器是不符合Servlet规范的,所以本文进一步描述一个简单的Servlet容器是怎么实现的 所以我们首先要明白Servlet接口规范,规范有不同版本,本人就先一视同仁了: pub ...
- Jsch
JSch is a pure Java implementation of SSH2. JSch allows you to connect to an sshd server and use por ...
- linux 的 scp 命令 可以 在 linux 之间复制 文件 和 目录
转自:http://blog.csdn.net/snlying/article/details/6184102 Linux系统中scp命令的用法. scp就是secure copy的简写,用于在lin ...
- 【tcl脚本】改变输出字符格式
需求: 原list输出格式 0x00 0x50 0x01 0x03 0x04 0x02 0x21 0x57 0x01 0x00 0x05 0x0B 0x03 0x13 0x00 0x01 要求list ...
- java懒汉式单例遇到多线程
单例模式确保某个类只有一个实例,而且自行实例化并向整个系统提供这个实例. 在计算机系统中,线程池.缓存.日志对象.对话框.打印机.显卡的驱动程序对象常被设计成单例.这些应用都或多或少具有资源管理器的功 ...
- Setting up Nutch 2.1 with MySQL to handle UTF-8
原文地址: http://nlp.solutions.asia/?p=180 These instructions assume Ubuntu 12.04 and Java 6 or 7 instal ...
- Sending messages to non-windowed applications -- AllocateHWnd, DeallocateHWnd
http://delphi.about.com/od/windowsshellapi/l/aa093003a.htm Page 1: How Delphi dispatches messages in ...
- Myeclipse如何整合tomcat
.在本机上安装MyEclipse和Tomcat 5软件程序 2.运行MyEclipse,设置与Tomcat 5服务器的连接,如下图所示: 选择Window--->Preferences,点击进入 ...
- Codeforces Round #311 (Div. 2)B. Pasha and Tea 水题
B. Pasha and Tea Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/557/prob ...
- hihocoder #1177 : 顺子 模拟
#1177 : 顺子 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://hihocoder.com/problemset/problem/1177 ...