✔ 最佳答案
使用Brute Force算法得出來的結果是74/105。
以下是算法的原代碼:
static int allCount = 0;
static int hitCount = 0;
void check(int a, int b, int c, int d, int e, int f, int g, int h)
{
a = a % 4;
b = b % 4;
c = c % 4;
d = d % 4;
e = e % 4;
f = f % 4;
g = g % 4;
h = h % 4;
if ((a == b) || (b == c) || (c == d) || (d == e) || (e == f) || (f == g) || (g == h) || (h == a))
{
hitCount++;
}
allCount++;
}
int _tmain(int argc, _TCHAR* argv[])
{
for (int a = 0; a < 8; a++) {
for (int b = 0; b < 8; b++) {
if (b != a) {
for (int c = 0; c < 8; c++) {
if ((c != a) && (c != b)) {
for (int d = 0; d < 8; d++) {
if ((d != a) && (d != b) && (d != c)){
for (int e = 0; e < 8; e++){
if ((e != a) && (e != b) && (e != c) && (e != d)){
for (int f = 0; f < 8; f++){
if ((f != a) && (f != b) && (f != c) && (f != d) && (f != e)){
for (int g = 0; g < 8; g++){
if ((g != a) && (g != b) && (g != c) && (g != d) && (g != e) && (g != f)){
for (int h = 0; h < 8; h++){
if ((h != a) && (h != b) && (h != c) && (h != d) && (h != e) && (h != f) && (h != g)){
check(a, b, c, d, e, f, g, h);
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
printf("%d/%d\n", hitCount/384, allCount/384);
}