C++ [KOI 2020]中的Minesweeper算法

发布于 2025-01-27 02:38:38 字数 1908 浏览 3 评论 0原文

我正在准备锦鲤2022,所以,我正在解决KOI 2021、2020问题。 KOI 2020竞赛1第1期问题5(请参阅在这里

我想制作< vector< vector< int>> Minesweeper(Vector< vector< int>>& v)功能,可在5*5 Minesweeper上使用。

参数

vector< vector< int>> & v

在扫雷器中转换为矢量的数字。 -1如果是空白。

例如{{0,0,1,-1,1},{-1,3,3,3,-1,1},{-1,-1,-1,-1,1,0},{2 ,5,-1、3,-1},{-1,-1,-1,-1,-1}}

返回值

a vector。大小与参数相同。我的是1,默认值为

0

有11个数字,其他数字为空白。

0011
331
02
53
마마

mine

A.

b.b.c.

d.e

E.

가 我也想要算法描述。

I'm preparing KOI 2022, so, I'm solving KOI 2021, 2020 problems. KOI 2020 contest 1 1st period problem 5(See problem 5 in here)

I want to make <vector<vector<int>> minesweeper(vector<vector<int>> &v) function that works on 5*5 minesweeper.

argument

vector<vector<int>> &v

Numbers in minesweeper that converted to vector. -1 if it is blank.

e.g. {{0, 0, 1, -1, 1}, {-1, 3, 3, -1, 1}, {-1, -1, -1, -1, 0}, {2, 5, -1, 3, -1}, {-1, -1, -1, -1, -1}}

return value

A vector. Size is same with argument. Mine is 1, default is 0.

English translation of KOI 2020 contest 1 1st period problem 5

There is a 5*5 minesweeper puzzle.

There are 11 numbers, and the others are blank.

0011
331
0
253

Where is the mine?

A. 가

B. 나

C. 다

D. 라

E. 마

How can I make minesweeper function? I want algorithm description, too.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心是晴朗的。 2025-02-03 02:38:39

有两个简单的规则来解决扫雷器:

  1. 如果一个字段看到了所有地雷,那么所有空白处都没有地雷,并且可以被发现。

  2. 如果一个字段的空白处与缺少矿山一样多,则它们都包含地雷。

不断地应用这些规则,直到什么都没有改变。

现在它变得复杂,因为您必须查看字段的组合。我建议直接进入蛮力算法,而不是弄清楚很多特殊案例:

对于一个知识字段旁边的每个空白字段:

  • 创建地图的副本,而不是
  • 返回在顶部解决每个地图,
  • 如果其中一个地图导致任何已知的领域都没有看到足够的地雷,那么另一个情况必须是实际解决方案,将其应用并返回开始,

如果没有取得进展,则必须猜测。上述循环可以为您提供矿山所在地点的概率,如果您知道总矿山的数量,则您对其他空白字段的可能性。选择最不可能有一个矿山的可能性。

There two some simple rules to solving Minesweeper:

  1. If a field sees all it's mines then all blank fields don't have mines and can be uncovered.

  2. If a field has as many blank fields as it is missing mines then they all contain mines.

Keep applying those rules over and over till nothing changes.

Now it gets complex because you have to look at combinations of fields. Instead of figuring out lots of special cases for 2, 3, 4 known fields I suggest going straight to a brute force algorithm:

For every blank field next to a know field:

  • create copies of the map with a mine present and not present
  • go back to the top to solve each map
  • if one of the maps results in any known field to not see enough mines then the other case must be the actual solution, apply it and go back to the start

If no progress was made then you have to guess. The above loop can give you probabilities for where mines are and if you know the number of mines total you have a probability for other blank fields. Pick one least likely to have a mine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文