英文题干

Sudoku is a logic-based, combinatorial number-placement puzzle. In classic Sudoku, the objective is to fill a 9 × 9 grid with digits so that each column, each row, and each of the nine 3 x 3 subgrids that compose the grid contains all of the digits from 1 to 9. The puzzle setter provides a partially completed grid, which for a well-posed puzzle has a single solution.

Minesweeper is a logic puzzle video game. The game features a grid of clickable tiles, with hidden mines scattered throughout the board. The objective is to clear the board without detonating any mines, with help from clues about the number of neighboring mines in each field.

You are given a solved classic Sudoku. You are asked to replace some numbers with mines so that the remaining numbers equal the number of neighboring mines. You can't replace all the numbers with mines.

Input:

The input contains 9 lines. Each line contains 9 characters. Each character is a number between 1 and 9.

The input describes the solved classic Sudoku.

Output:

Output 9 lines, denoting the answer.

Each line contains 9 characters. Each character is either a number between 1 and 9 or '*' (which represents a mine).

中文题干

数独是一个基于逻辑的组合数字放置谜题。在经典数独中,目标是用数字填充 9×9 网格,以便组成网格的 9 个 3x3 子网格中的每列、每行和每个子网格都包含从 1 到 9 的所有数字。谜题设置器提供了一个部分完成的网格,对于一个摆好姿势的谜题,它有一个单一的解决方案。

扫雷是一款逻辑益智视频游戏。该游戏有一个可点击的瓷砖网格,隐藏的地雷散布在整个棋盘上。目标是在不引爆任何地雷的情况下清除棋盘,并借助有关每个领域中相邻地雷数量的线索。

你会得到一个已解决的经典数独。你被要求用地雷替换一些数字,以便剩余的数字等于相邻地雷的数量。你不能用地雷替换所有的数字。

思路

一道简单的签到题

  1. 题目只要求找出一种满足条件(不全为雷)的情况即可。又因为原图是数独,故每一行必然存在一个 8,而 8 在扫雷中代表周围全都是雷,我们只需保留一个这样的 8,其他全部替换为雷即可。

AC代码

时间复杂度:O()

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int infmin = 0xc0c0c0c0;
const int infmax = 0x3f3f3f3f;
const int maxn = 10;

char g[maxn][maxn];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            cin >> g[i][j];
        }
    }

    int x = 0, y = 0;
    bool isok = 0;
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            if (i != 1 && i != 9 && j != 1 && j != 9 && g[i][j] == '8') {  // 只保留一个8即可
                x = i, y = j;
                isok = 1;
                break;
            }
        }

        if (isok)
            break;
    }

    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            if (i == x && j == y)
                cout << 8;
            else
                cout << "*";
        }
        cout << endl;
    }

    return 0;
}