I Hard Math Problem
题目链接:https://ac.nowcoder.com/acm/contest/5670/I
题目描述
You are a player of the game Mine Craft. As a lawful good player, instead of droping TNT everywhere you want to build your village on a vast plain.
The game map could be recognized as a rectangle grid. In one grid, you can set up a gold miner, or an elixir collector, or a headquarter. You also can leave some grids green and vibrant.
However, one restriction for some good reasons is that a headquarter must be next to at least one gold miner and at least one elixir collector. ‘Next to’ means that their grids share one side – every grid is next to up, down, left, and right grids.
“Effeciecy!” A good old man said to you. You, the vast plain holder, want to be the most effecient player in the server. You want to maximize the number of headquarters in your village. Formally, If the village is a grid of size
n
×
m
n \times m
n×m, we define the max number of headquarters can be built as f(n,m). For example, f(1,1) = 0 ,since there should be at least 3 grids for setting up a headquarter; f(1,6) = 2 and one possible solution is
(
G
,
H
,
E
,
G
,
H
,
E
)
.
(G,\ H,\ E,\ G,\ H,\ E).
(G, H, E, G, H, E).
To prove that you really understand the problem very well, print the efficiency on the infinite plain. Formally, you need to calculate
lim
n
→
∞
lim
m
→
∞
f
(
n
,
m
)
n
⋅
m
\lim_{n\to\infty} \lim_{m\to\infty} \frac{f(n,m)}{n\cdot m}
limn→∞limm→∞n⋅mf(n,m).
输入描述:
No input.
输出描述:
A real number denoting the answer to the question. Round the answer to 6 decimal places. For example, if your answer is 0.123456789, print 0.123457.
题面:
思路
官方题解
解释一下:
因为求的是n和m都趋近无穷的情况下,所以边界情况可以不看。即边界可以看做就是符合的。那么题解给的情况就是
对于(i+j)%3=0的位置就放G和E,交叉着放,这样子就满足条件,每一个H 旁边有至少一个G和一个E,每个G和E都不相邻。(这里注意斜着的并不是相邻,上面第一排画出的上面应该还有,即先前所说的边界都是满足的意思)
可以看出每三个里有2个H,所以就可以看出是
2
3
2\over3
32。
还有种看法就是转个方向看
在斜线上交错摆E和G,而斜线上测和下测都可以摆放H,这样占比最大且满足条件。所以还是可以看做三条斜线有两条都是H,趋近无穷就是
2
3
2\over3
32。
代码
略,输出0.666667即可。