<legend id='obLNR'><style id='obLNR'><dir id='obLNR'><q id='obLNR'></q></dir></style></legend>
  • <i id='obLNR'><tr id='obLNR'><dt id='obLNR'><q id='obLNR'><span id='obLNR'><b id='obLNR'><form id='obLNR'><ins id='obLNR'></ins><ul id='obLNR'></ul><sub id='obLNR'></sub></form><legend id='obLNR'></legend><bdo id='obLNR'><pre id='obLNR'><center id='obLNR'></center></pre></bdo></b><th id='obLNR'></th></span></q></dt></tr></i><div id='obLNR'><tfoot id='obLNR'></tfoot><dl id='obLNR'><fieldset id='obLNR'></fieldset></dl></div>

      • <bdo id='obLNR'></bdo><ul id='obLNR'></ul>
      <tfoot id='obLNR'></tfoot>
      1. <small id='obLNR'></small><noframes id='obLNR'>

        将 9x9 2d 数组划分为 9 个子网格(如数独)?(C++)

        时间:2023-09-15
      2. <small id='jWrRK'></small><noframes id='jWrRK'>

        <i id='jWrRK'><tr id='jWrRK'><dt id='jWrRK'><q id='jWrRK'><span id='jWrRK'><b id='jWrRK'><form id='jWrRK'><ins id='jWrRK'></ins><ul id='jWrRK'></ul><sub id='jWrRK'></sub></form><legend id='jWrRK'></legend><bdo id='jWrRK'><pre id='jWrRK'><center id='jWrRK'></center></pre></bdo></b><th id='jWrRK'></th></span></q></dt></tr></i><div id='jWrRK'><tfoot id='jWrRK'></tfoot><dl id='jWrRK'><fieldset id='jWrRK'></fieldset></dl></div>
      3. <tfoot id='jWrRK'></tfoot>

              <tbody id='jWrRK'></tbody>
              <legend id='jWrRK'><style id='jWrRK'><dir id='jWrRK'><q id='jWrRK'></q></dir></style></legend>
                • <bdo id='jWrRK'></bdo><ul id='jWrRK'></ul>

                • 本文介绍了将 9x9 2d 数组划分为 9 个子网格(如数独)?(C++)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试编写数独求解器的代码,我尝试这样做的方法是拥有一个 9x9 的指针网格,其中包含拥有解决方案或有效可能值的设置"对象的地址.

                  I'm trying to code a sudoku solver, and the way I attempted to do so was to have a 9x9 grid of pointers that hold the address of "set" objects that posses either the solution or valid possible values.

                  我能够通过 2 个 for 循环遍历数组,首先遍历每一列,然后转到下一行并重复.

                  I was able to go through the array with 2 for loops, through each column first and then going to the next row and repeating.

                  但是,我很难想象如何指定特定单元格属于哪个子网格(或框、块等).我最初的印象是在 for 循环中有 if 语句,例如 if row <2 (行从 0 开始) &颜色 <2 然后我们在第一个街区,但这似乎变得混乱.有没有更好的方法来做到这一点?

                  However, I'm having a hard time imagining how I would designate which sub-grid (or box, block etc) a specific cell belongs to. My initial impression was to have if statements in the for loops, such as if row < 2 (rows start at 0) & col < 2 then we're in the 1st block, but that seems to get messy. Would there be a better way of doing this?

                  推荐答案

                  您可以像这样从行和列计算块编号:

                  You could calculate a block number from row and column like this:

                  int block = (row/3)*3 + (col/3);
                  

                  这样对块进行编号:

                  +---+---+---+
                  | 0 | 1 | 2 |
                  +---+---+---+
                  | 3 | 4 | 5 |
                  +---+---+---+
                  | 6 | 7 | 8 |
                  +---+---+---+
                  

                  这篇关于将 9x9 2d 数组划分为 9 个子网格(如数独)?(C++)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 C++ 的二维数组 下一篇:C++:获取传递给函数的多维数组的行大小

                  相关文章

                  最新文章

                  <tfoot id='QKhOu'></tfoot>
                    <bdo id='QKhOu'></bdo><ul id='QKhOu'></ul>

                  1. <legend id='QKhOu'><style id='QKhOu'><dir id='QKhOu'><q id='QKhOu'></q></dir></style></legend>

                    <small id='QKhOu'></small><noframes id='QKhOu'>

                      <i id='QKhOu'><tr id='QKhOu'><dt id='QKhOu'><q id='QKhOu'><span id='QKhOu'><b id='QKhOu'><form id='QKhOu'><ins id='QKhOu'></ins><ul id='QKhOu'></ul><sub id='QKhOu'></sub></form><legend id='QKhOu'></legend><bdo id='QKhOu'><pre id='QKhOu'><center id='QKhOu'></center></pre></bdo></b><th id='QKhOu'></th></span></q></dt></tr></i><div id='QKhOu'><tfoot id='QKhOu'></tfoot><dl id='QKhOu'><fieldset id='QKhOu'></fieldset></dl></div>