HBC214893逃脱,深度优先搜索(DFS),搜索MineSweeperII题解

凌晚轩 算法基础篇 29 0
想要检验自己的编程水平?来试试全网最全C++题库,让您在挑战中不断进步。
A mine-sweeper map X{X}X can be expressed as an n×mntimes mn×m grid. Each cell of the grid is either a mine cell or a non-mine cell. A mine cell has no number on it. Each non-mine cell has a number representing the number of mine cells around it. The following is a 16×3016times 3016×30 mine-sweeper map where a flagged cell denotes a mine cell and a blank cell denotes a non-mine cell with number 0. Given two mine-sweeper maps A,B{A, B}A,B of size n×mntimes mn×m, you should modify at most nm2leftlfloorfrac{nm}{2}rightrfloor2nm cells in B{B}B such that the sum of numbers in the non-mine cells in A{A}A and the sum of numbers in the non-mine cells in B{B}B are the same. If multiple solutions exist, print any of them. If no solution exists, print ''-1'' in one line.

A mine-sweeper map X{X}X can be expressed as an n×mntimes mn×m grid. Each cell of the grid is either a mine cell or a non-mine cell. A mine cell has no number on it. Each non-mine cell has a number representing the number of mine cells around it. (A cell is around another cell if they share at least one common point. Thus, every cell that is not on the boundary has 8 cells around it.) The following is a 16×3016times 3016×30 mine-sweeper map where a flagged cell denotes a mine cell and a blank cell denotes a non-mine cell with number 0. Given two mine-sweeper maps A,B{A, B}A,B of size n×mntimes mn×m, you should modify at most ⌊nm2⌋leftlfloorfrac{nm}{2}rightrfloor⌊2nm​⌋ (i.e. the largest nonnegative integer that is less than or equal to nm2frac{nm}{2}2nm​) cells in B{B}B (from a non-mine cell to a mine cell or vice versa) such that the sum of numbers in the non-mine cells in A{A}A and the sum of numbers in the non-mine cells in B{B}B are the same. (If a map has no non-mine cell, the sum is considered as 0.) If multiple solutions exist, print any of them. If no solution exists, print ''-1'' in one line.

HBC214893逃脱,深度优先搜索(DFS),搜索MineSweeperII题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断挑战自我,才能突破极限!全网最全C++题库,让您在编程道路上越走越远。

标签: HBC214893逃脱 深度优先搜索(DFS) 搜索MineSweeperII题解