81 lines
2.7 KiB
C++
81 lines
2.7 KiB
C++
#include <bits/stdc++.h>
|
||
|
||
using namespace std;
|
||
typedef long long LL;
|
||
|
||
int x[4] = {1, 2, 3, 4};
|
||
const int N = 110;
|
||
int a[N][4];
|
||
int size;
|
||
|
||
//填充一个全排列二维数组
|
||
void fill_qpl() {
|
||
do {
|
||
a[size][0] = x[0], a[size][1] = x[1], a[size][2] = x[2], a[size++][3] = x[3];
|
||
} while (next_permutation(x, x + 4));
|
||
}
|
||
|
||
int bucket[5];
|
||
|
||
bool check(int a[4], int b[4], int c[4], int d[4]) {
|
||
//左上
|
||
memset(bucket, 0, sizeof bucket);
|
||
bucket[a[0]]++, bucket[a[1]]++, bucket[b[0]]++, bucket[b[1]]++;
|
||
for (int i = 1; i <= 4; i++)if (bucket[i] != 1) return false;
|
||
//右上
|
||
memset(bucket, 0, sizeof bucket);
|
||
bucket[a[2]]++, bucket[a[3]]++, bucket[b[2]]++, bucket[b[3]]++;
|
||
for (int i = 1; i <= 4; i++)if (bucket[i] != 1) return false;
|
||
//左下
|
||
memset(bucket, 0, sizeof bucket);
|
||
bucket[c[0]]++, bucket[c[1]]++, bucket[d[0]]++, bucket[d[1]]++;
|
||
for (int i = 1; i <= 4; i++)if (bucket[i] != 1) return false;
|
||
//右下
|
||
memset(bucket, 0, sizeof bucket);
|
||
bucket[c[2]]++, bucket[c[3]]++, bucket[d[2]]++, bucket[d[3]]++;
|
||
for (int i = 1; i <= 4; i++)if (bucket[i] != 1) return false;
|
||
|
||
//竖着也需要检查噢~
|
||
for (int k = 0; k < 4; k++) {
|
||
memset(bucket, 0, sizeof bucket);
|
||
bucket[a[k]]++, bucket[b[k]]++, bucket[c[k]]++, bucket[d[k]]++;
|
||
for (int i = 1; i <= 4; i++)if (bucket[i] != 1) return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
int cnt;
|
||
|
||
int main() {
|
||
//填充
|
||
fill_qpl();
|
||
|
||
for (int i = 0; i < size; i++)
|
||
for (int j = 0; j < size; j++)
|
||
for (int k = 0; k < size; k++)
|
||
for (int p = 0; p < size; p++) {
|
||
//四行数据
|
||
//a[i],a[j],a[k],a[p] 是否可以构成数独?
|
||
//构建的矩阵,切割成四块,每块用桶的思路看看是不是满足1,2,3,4分布
|
||
if (i == j || i == k || i == p || j == k || j == p || k == p) continue;
|
||
|
||
if (check(a[i], a[j], a[k], a[p])) {
|
||
//输出
|
||
for (int m = 0; m < 4; m++) cout << a[i][m] << " ";
|
||
cout << endl;
|
||
for (int m = 0; m < 4; m++) cout << a[j][m] << " ";
|
||
cout << endl;
|
||
for (int m = 0; m < 4; m++) cout << a[k][m] << " ";
|
||
cout << endl;
|
||
for (int m = 0; m < 4; m++) cout << a[p][m] << " ";
|
||
cout << endl;
|
||
cout << endl;
|
||
|
||
//计数
|
||
cnt++;
|
||
}
|
||
}
|
||
|
||
cout << cnt << endl;
|
||
return 0;
|
||
} |