一.破碎的砝码
1.枚举
#include<stdio.h>
#define num_count 300
typedef struct data {
int num1;
int num2;
int num3;
int num4;
}data;
data dt[num_count];
int index = 0;
void findNum() {
int i, j, k;
i = 1;
j = i + 1;
k = j + 1;
for (i = 1; i <= 34, i < j, i < k; i++)
for (j = i + 1; j <= 40 - i, j < k; j++)
if (j != i)
for (k = j + 1; k <= 40 - i - j; k++)
if (k != j && k != i) {
int temp = 40 - i - j - k;
if (temp != i && temp != j && temp != k && temp > k) {
dt[index].num1 = i;
dt[index].num2 = j;
dt[index].num3 = k;
dt[index].num4 = temp;
index++;
}
}
}
int isequal(data dt,int target) {
int arr[3] = { -1,0,1 };
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
for (int k = 0; k < 3; k++)
for (int p = 0; p < 3; p++)
if (arr[i] * dt.num1 + arr[j] * dt.num2 + arr[k] * dt.num3 + arr[p] * dt.num4 == target)
return 1;
return 0;
}
void judge() {
int i, j;
for (i = 0; i < index; i++) {
for (j = 1; j <= 40; j++)
if(!(isequal(dt[i], j)))
break;
if (j > 40)
printf("(%d,%d,%d,%d)\n", dt[i].num1, dt[i].num2, dt[i].num3, dt[i].num4);
}
}
int main() {
findNum();
judge();
return 0;
}