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 ...
随机推荐
- 使用maphilight高亮显示map的指定area
引用jquery.maphilight.js之后,调用如下方法: //obj参数是代表一个或者多个area的jQuery对象 function areaLight(obj) { var data = ...
- Visual Studio 2012 主题下的代码配色方案
默认的VS2012的深色配色方案个人感觉很丑,不是很好看,于是就自己动手配置了一下,突出语法高亮显示,增加代码语法识别度,个人感觉还是可以的. 原来使用的是VAX,但自从VAX导致的我的VS不能输入中 ...
- yum update Transaction Check Error
update系统时,发现其中一台server居然提示: Transaction Check Error:file /usr/lib/perl5/5.8.8/CGI.pm from install of ...
- Visual Studio 2015 和 Apache Cordova
英文原版:http://www.codeproject.com/Articles/860150/Visual-Studio-and-Apache-Cordova 在开始前,问一下自己下面这些问题: 熟 ...
- .net中怎么使用CKEditor
1:官网下载Full Package2:将此ckeditor文件包拷贝到项目根目录下3:CKEditor 3.6.6.2 for ASP.NET下载4:复制_Samples\bin\Release\C ...
- XianBicycle
https://github.com/xialinchong/secrettalkandroid https://github.com/talentprince/PhotoView https://g ...
- 微信lbs---返回两个经纬度坐标点的距离
微信开发:lbs附近的商家,在数据库里记录商家的坐标,lbs设置里管理搜索半径,查询的时候,查询 客户当前坐标的半径内的所有商家列表.个人喜欢不一样,我选择了执行sql ,毕竟效果高点.微信开发必须得 ...
- vs2013 设置为中文版
- android百度地图开发之自动定位所在位置与固定位置进行驾车,步行,公交路线搜索
最近跟着百度地图API学地图开发,先是学了路径搜索,对于已知坐标的两点进行驾车.公交.步行三种路径的搜索(公交路径运行没效果,待学习中),后来又 学了定位功能,能够获取到自己所在位置的经纬度,但当将两 ...
- vm内核参数优化设置
http://www.cnblogs.com/wjoyxt/archive/2014/06/08/3777042.html (1)vm.overcommit_memory 执行grep -i com ...