English 中文(简体)
将9x9 2d阵列分成9个分网(如 s湖)吗? (C++)
原标题:Dividing a 9x9 2d array into 9 sub-grids (like in sudoku)? (C++)
  • 时间:2011-01-17 21:41:07
  •  标签:
  • c++
  • sudoku

我试图编造一个ud溶器,而我试图这样做的方式是拥有9x9个电线器的电网,该电线标有“set”物体的地址,这些物体要么放弃解决办法,要么具有可行的价值。

我能够先通过每栏两栏,然后进入下行和重复。

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?

最佳回答

您可从行文中计算一个栏号:

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

这些数字是:

+---+---+---+
| 0 | 1 | 2 |
+---+---+---+
| 3 | 4 | 5 |
+---+---+---+
| 6 | 7 | 8 |
+---+---+---+
问题回答

我将编制一个有81个条目的调查表。 每一条目都指9x9电网中的电池,并向你提供所需信息(方框,一栏,行......)

我使用我的话(当时在座,假定X和0至9分):

int bx, by;
for (bx = (x/3)*3; bx < (x/3)*3 + 3; bx++) {
    for (by = (y/3)*3; by < (y/3)*3 + 3; by++) {
        // bx and by will now loop over each number in the block which also contains x, y
    }
}




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签