题解:2024牛客多校第三场 L
L Sudoku and Minesweeper
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 1048576K,其他语言2097152K
Special Judge, 64bit IO Format: %lld
题目描述
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 × 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.
数独是一种基于逻辑的组合数字排位谜题。在经典的数独游戏中,谜题的目的是在一个 \(9 × 9\) 的网格中填入数字,使每一列、每一行以及组成网格的九个 \(3 × 3\) 子网格中的每一个都包含从 \(1\) 到 \(9\) 的所有数字。谜题设置者会提供一个部分完成的网格,对于一个摆好的谜题来说,它只有一个解。
扫雷是一款逻辑益智类视频游戏。游戏的特点是由一个个可点击的方格组成,棋盘上散布着隐藏的地雷。游戏的目标是在不引爆任何地雷的情况下清除棋盘上的地雷,而每个区域内相邻地雷的数量则会提供线索。
给您一个已解的经典数独。要求您用地雷替换一些数字,使剩余的数字等于相邻地雷的数量。您不能用地雷替换所有数字。
输入描述:
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.
输入内容包含 \(9\) 行。每行包含 \(9\) 个字符。每个字符都是介于 \(1\) 和 \(9\) 之间的数字。
输入内容描述了已解出的经典数独。
输出描述:
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\) 个字符。每个字符要么是 \(1\) 到 \(9\) 之间的数字,要么是 *
(代表地雷)。
示例1
输入
123647859
648295317
795831642
436578921
981462573
257913486
319754268
572386194
864129735
输出
123******
*4*******
**5***642
**65***21
****6*5*3
*****34**
****54*6*
*****6**4
*********
(由于语法原因,输出的格式略显不同)
题解
by Krebet
因为是数独,所以除了边缘部分,其余部分一定至少含有一个 \(8\)
只要除了这个 \(8\) 以外的所有格子都变成地雷就可以了
代码
#include <iostream>
#include <string>
int main() {
std::string s[9];
for(int i = 0 ; i < 9 ; i ++) std::cin >> s[i];
int x,y;
int jud = 1;
for(int i = 1 ; i + 1 < 9 && jud; i ++) {
for(int j = 1 ; j + 1 < 9 && jud; j ++) {
if(s[i][j] == '8') {
x = i;
y = j;
jud = 0;
}
}
}
for(int i = 0 ; i < 9 ; i ++) {
for(int j = 0 ; j < 9 ; j ++) {
if(x == i && y == j) {
std::cout << '8';
} else {
std::cout << '*';
}
}
std::cout << "\n";
}
return 0;
}
posted on 2024-07-24 14:59 Jiejiejiang 阅读(9) 评论(0) 编辑 收藏 举报