先来看看今天很火的2018年刑侦科目推理试题:
解法貌似很多,这里贴上技术宅的解法,有点意思。
大神用用java写的,把这些逻辑全部转换成数字,简单粗暴的遍历所有可能,就得出结论了。
[code]
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import sun.management.counter.Variability;
public class Test {
public static void main(String[] para) {
int[] arr;
int p0 = pow(4, 0);
int p1 = pow(4, 1);
int p2 = pow(4, 2);
int p3 = pow(4, 3);
int p4 = pow(4, 4);
int p5 = pow(4, 5);
int p6 = pow(4, 6);
int p7 = pow(4, 7);
int p8 = pow(4, 8);
int p9 = pow(4, 9);
List<int[]> success_arrs = new ArrayList<int[]>();
for (int i = 0; i < pow(4, 10); i++) {
arr = new int[11];
// 为了方便理解,数组从下标1开始,数据从1到4分别对应ABCD
arr[1] = i / p0 % 4 + 1;
arr[2] = i / p1 % 4 + 1;
arr[3] = i / p2 % 4 + 1;
arr[4] = i / p3 % 4 + 1;
arr[5] = i / p4 % 4 + 1;
arr[6] = i / p5 % 4 + 1;
arr[7] = i / p6 % 4 + 1;
arr[8] = i / p7 % 4 + 1;
arr[9] = i / p8 % 4 + 1;
arr[10] = i / p9 % 4 + 1;
System.out.print("检测数组:");
for (int j = 1; j <= 10; j++) {
System.out.print(arr[j] + ", ");
}
System.out.println();
// 开始检测
if (test_all(arr)) {// 符合规则
success_arrs.add(arr);
}
}
System.out.print("成功匹配" + success_arrs.size() + "个!");
for (int j = 0; j < success_arrs.size(); j++) {
int[] sa = success_arrs.get(j);
System.out.print("成功匹配的数组:");
for (int k = 1; k <= 10; k++) {
System.out.print(sa[k] + ", ");
}
System.out.println();
}
}
// 计算整数的幂
private static int pow(int a, int b) {
int result = 1;
for (int k = 0; k < b; k++) {
result = result * a;
}
return result;
}
// 测试是否符合规则
private static boolean test_all(int[] arr) {
// 第1题不需要判断
// 第2题
boolean b2 = ((arr[2] == 1 && arr[5] == 3)
|| (arr[2] == 2 && arr[5] == 4) || (arr[2] == 3 && arr[5] == 1) || (arr[2] == 4 && arr[5] == 2));
// 第3题
boolean b3 = ((arr[3] == 1 && arr[6] == arr[2] && arr[6] == arr[4] && arr[6] != arr[3])
|| (arr[3] == 2 && arr[3] == arr[2] && arr[3] == arr[4] && arr[3] != arr[6])
|| (arr[3] == 3 && arr[3] == arr[6] && arr[3] == arr[4] && arr[3] != arr[2]) || (arr[3] == 4
&& arr[3] == arr[6] && arr[3] == arr[2] && arr[3] != arr[4]));
// 第4题
boolean b4 = ((arr[4] == 1 && (arr[1] == arr[5]))
|| (arr[4] == 2 && (arr[2] == arr[7]))
|| (arr[4] == 3 && (arr[1] == arr[9])) || (arr[4] == 4 && (arr[6] == arr[10])));
// 第5题
boolean b5 = ((arr[5] == 1 && (arr[8] == 1))
|| (arr[5] == 2 && (arr[4] == 2))
|| (arr[5] == 3 && (arr[9] == 3)) || (arr[5] == 4 && (arr[7] == 4)));
// 第6题
boolean b6 = ((arr[6] == 1 && (arr[8] == arr[2] && arr[8] == arr[4]))
|| (arr[6] == 2 && (arr[8] == arr[1] && arr[8] == arr[6]))
|| (arr[6] == 3 && (arr[8] == arr[3] && arr[8] == arr[10])) || (arr[6] == 4 && (arr[8] == arr[8] && arr[5] == arr[9])));
// 第7题
int[] count_num = { 0, 0, 0, 0, 0 };// 各选项计数,实际只使用了下标1到4的
for (int k = 1; k <= 10; k++) {
count_num[arr[k]]++;
}
int max_number = count_num[1];
int min_number = count_num[1];
int max_index = 1;
int min_index = 1;
for (int k = 1; k <= 4; k++) {
if (count_num[k] > max_number) {
max_number = count_num[k];
max_index = k;
}
if (count_num[k] < min_number) {
min_number = count_num[k];
min_index = k;
}
}
boolean b7 = ((arr[7] == 1 && (min_index == 3))
|| (arr[7] == 2 && (min_index == 2))
|| (arr[7] == 3 && (min_index == 1)) || (arr[7] == 4 && (min_index == 4)));
// 第8题
boolean b8 = ((arr[8] == 1 && (arr[7] - arr[1] != 1 && arr[7] - arr[1] != -1))
|| (arr[8] == 2 && (arr[5] - arr[1] != 1 && arr[5] - arr[1] != -1))
|| (arr[8] == 3 && (arr[2] - arr[1] != 1 && arr[2] - arr[1] != -1)) || (arr[8] == 4 && (arr[10]
- arr[1] != 1 && arr[10] - arr[1] != -1)));
// 第9题
boolean b9 = ((arr[9] == 1 && ((arr[1] == arr[6]) != (arr[6] == arr[5])))
|| (arr[9] == 2 && ((arr[1] == arr[6]) != (arr[10] == arr[5])))
|| (arr[9] == 3 && ((arr[1] == arr[6]) != (arr[2] == arr[5]))) || (arr[9] == 4 && ((arr[1] == arr[6]) != (arr[9] == arr[5]))));
// 第10题
boolean b10 = ((arr[10] == 1 && (max_number - min_number == 3))
|| (arr[10] == 2 && (max_number - min_number == 2))
|| (arr[10] == 3 && (max_number - min_number == 4)) || (arr[10] == 4 && (max_number
- min_number == 1)));
return b2 && b3 && b4 && b5 && b6 && b7 && b8 && b9 && b10;
}
}
[/code]
运行后的结果是:
成功匹配1个!成功匹配的数组:2, 3, 1, 3, 1, 3, 4, 1, 2, 1,
即答案是:BCACACDABA
欢迎转载,请保留出处,谢谢!