26d063757dce897be4a11427618b9ba.png
看到2018年刑侦科推理试题,一下子蒙住了,还有这种题?这么变态!但有过公务员考试经历的,一眼就能看出,这是标准的逻辑题。
那咱就用程序来解决吧!
分析:
1.10道题,每道题答案是abcd中的一个,总共的情况也不过是4的10次方。我们把每一种情况都试一次,肯定能找到正确答案。
2.10道题,每道题对应数组的一个下标,那么就是一个长度为10的数组,每一个数组就是一种情况。
3.10道题的限制条件都通过的数组,就是我们需要的数组。
附代码:虽然代码不是很优秀,但至少解决了问题,也是我个人心血的结晶。
运行时 只需要调用#chooseArray()方法即可。
public class MyTest {
private static final String TAG = "MTest";
String[] strs = {"A", "B", "C", "D"};
String[] aimArray = new String[10];
/**
* 根据i确定数组
*
* @param i
*/
public void getAimArray(int i, int j, int k, int l, int m, int n, int o, int p, int q, int r) {
aimArray[0] = strs[i];
aimArray[1] = strs[j];
aimArray[2] = strs[k];
aimArray[3] = strs[l];
aimArray[4] = strs[m];
aimArray[5] = strs[n];
aimArray[6] = strs[o];
aimArray[7] = strs[p];
aimArray[8] = strs[q];
aimArray[9] = strs[r];
}
public void chooseArray() {
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
for (int l = 0; l < 4; l++) {
for (int m = 0; m < 4; m++) {
for (int n = 0; n < 4; n++) {
for (int o = 0; o < 4; o++) {
for (int p = 0; p < 4; p++) {
for (int q = 0; q < 4; q++) {
for (int r = 0; r < 4; r++) {
if (checkArray(i, j, k, l, m, n, o, p, q, r)) {
Log.e(TAG, "chooseArray: " + Arrays.toString(aimArray));
}
}
}
}
}
}
}
}
}
}
}
}
private boolean checkArray(int i, int j, int k, int l, int m, int n, int o, int p, int q, int r) {
getAimArray(i, j, k, l, m, n, o, p, q, r);
//条件判断
//第3题判断 存在且唯一 一道题的答案与其他三到题答案不同 且答案为第三题
if ((aimArray[2] != aimArray[5] && aimArray[2] != aimArray[1] && aimArray[2] != aimArray[3] && aimArray[2] == strs[0])
|| (aimArray[5] != aimArray[2] && aimArray[5] != aimArray[1] && aimArray[5] != aimArray[3] && aimArray[2] == strs[1])
|| (aimArray[1] != aimArray[2] && aimArray[1] != aimArray[5] && aimArray[1] != aimArray[3] && aimArray[2] == strs[2])
|| (aimArray[3] != aimArray[2] && aimArray[3] != aimArray[5] && aimArray[3] != aimArray[1] && aimArray[2] == strs[3])) {
//第4题判断 存在且唯一 两道题答案相同 且答案为第四题
if ((aimArray[0] == aimArray[4] && aimArray[1] != aimArray[6] && aimArray[0] != aimArray[8] && aimArray[5] != aimArray[9] && aimArray[3] == strs[0])
|| (aimArray[0] != aimArray[4] && aimArray[1] == aimArray[6] && aimArray[0] != aimArray[8] && aimArray[5] != aimArray[9] && aimArray[3] == strs[1])
|| (aimArray[0] != aimArray[4] && aimArray[1] != aimArray[6] && aimArray[0] == aimArray[8] && aimArray[5] != aimArray[9] && aimArray[3] == strs[2])
|| (aimArray[0] != aimArray[4] && aimArray[1] != aimArray[6] && aimArray[0] != aimArray[8] && aimArray[5] == aimArray[9] && aimArray[3] == strs[3])) {
//第5题判断 存在且唯一 哪一题答案与第五题相同 且为第五题答案
if (aimArray[4] == aimArray[7] && aimArray[4] != aimArray[3] && aimArray[4] != aimArray[8] && aimArray[4] != aimArray[6]
|| aimArray[4] != aimArray[7] && aimArray[4] == aimArray[3] && aimArray[4] != aimArray[8] && aimArray[4] != aimArray[6]
|| aimArray[4] != aimArray[7] && aimArray[4] != aimArray[3] && aimArray[4] == aimArray[8] && aimArray[4] != aimArray[6]
|| aimArray[4] != aimArray[7] && aimArray[4] != aimArray[3] && aimArray[4] != aimArray[8] && aimArray[4] == aimArray[6]) {
//第6题判断 存在且唯一 第哪两题答案与第八题相同 且答案为第六题
if ((aimArray[7] == aimArray[1] && aimArray[7] == aimArray[3]
&& (aimArray[7] != aimArray[0] || aimArray[7] != aimArray[5])
&& (aimArray[7] != aimArray[2] || aimArray[7] != aimArray[9])
&& (aimArray[7] != aimArray[4] || aimArray[7] != aimArray[8])
&& aimArray[5] == strs[0])
|| (aimArray[7] == aimArray[0] && aimArray[7] == aimArray[5]
&& (aimArray[7] != aimArray[1] || aimArray[7] != aimArray[3])
&& (aimArray[7] != aimArray[2] || aimArray[7] != aimArray[9])
&& (aimArray[7] != aimArray[4] || aimArray[7] != aimArray[8])
&& aimArray[5] == strs[1])
|| (aimArray[7] == aimArray[2] && aimArray[7] == aimArray[9]
&& (aimArray[7] != aimArray[1] || aimArray[7] != aimArray[3])
&& (aimArray[7] != aimArray[0] || aimArray[7] != aimArray[5])
&& (aimArray[7] != aimArray[4] || aimArray[7] != aimArray[8])
&& aimArray[5] == strs[2])
|| (aimArray[7] == aimArray[4] && aimArray[7] == aimArray[8]
&& (aimArray[7] != aimArray[1] || aimArray[7] != aimArray[3])
&& (aimArray[7] != aimArray[0] || aimArray[7] != aimArray[5])
&& (aimArray[7] != aimArray[2] || aimArray[7] != aimArray[9])
&& aimArray[5] == strs[3])) {
//第7题 选中次数最少的字母
if (aimArray[6] == less()) {
//第10题 abcd 出现最多与最少的差
if (aimArray[9] == more()) {
//第9题 真假性相反
if ((aimArray[0] == aimArray[5] && (
(aimArray[5] != aimArray[4] && aimArray[9] == aimArray[4] && aimArray[1] == aimArray[4] && aimArray[8] == aimArray[4] && aimArray[8] == strs[0])
|| (aimArray[9] != aimArray[4] && aimArray[5] == aimArray[4] && aimArray[1] == aimArray[4] && aimArray[8] == aimArray[4] && aimArray[8] == strs[1])
|| (aimArray[1] != aimArray[4] && aimArray[9] == aimArray[4] && aimArray[5] == aimArray[4] && aimArray[8] == aimArray[4] && aimArray[8] == strs[2])
|| (aimArray[8] != aimArray[4] && aimArray[9] == aimArray[4] && aimArray[1] == aimArray[4] && aimArray[5] == aimArray[4] && aimArray[8] == strs[3])
))
|| (aimArray[0] != aimArray[5] && ((
(aimArray[5] == aimArray[4] && aimArray[9] != aimArray[4] && aimArray[1] != aimArray[4] && aimArray[8] != aimArray[4] && aimArray[8] == strs[0])
|| (aimArray[9] == aimArray[4] && aimArray[5] != aimArray[4] && aimArray[1] != aimArray[4] && aimArray[8] != aimArray[4] && aimArray[8] == strs[1])
|| (aimArray[1] == aimArray[4] && aimArray[9] != aimArray[4] && aimArray[5] != aimArray[4] && aimArray[8] != aimArray[4] && aimArray[8] == strs[2])
|| (aimArray[8] == aimArray[4] && aimArray[9] != aimArray[4] && aimArray[1] != aimArray[4] && aimArray[5] != aimArray[4] && aimArray[8] == strs[3])
)))) {
//第2题 第五题答案 第二题答案
if ((aimArray[4] == strs[2] && aimArray[1] == strs[0])
|| (aimArray[4] == strs[3] && aimArray[1] == strs[1])
|| (aimArray[4] == strs[0] && aimArray[1] == strs[2])
|| (aimArray[4] == strs[1] && aimArray[1] == strs[3])) {
return true;
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
private String less() {
int a = 0;
int b = 0;
int c = 0;
int d = 0;
for (int i = 0; i < 10; i++) {
if (aimArray[i] == strs[0]) {
a++;
}
if (aimArray[i] == strs[1]) {
b++;
}
if (aimArray[i] == strs[2]) {
c++;
}
if (aimArray[i] == strs[3]) {
d++;
}
}
if (a < b && a < c && a < d) {
return strs[2];
} else if (b < a && b < c && b < d) {
return strs[1];
} else if (c < a && c < b && c < d) {
return strs[0];
} else if (d < a && d < b && d < c) {
return strs[3];
} else {
return strs[0];
}
}
private String more() {
int a = 0;
int b = 0;
int c = 0;
int d = 0;
for (int i = 0; i < 10; i++) {
if (aimArray[i] == strs[0]) {
a++;
}
if (aimArray[i] == strs[1]) {
b++;
}
if (aimArray[i] == strs[2]) {
c++;
}
if (aimArray[i] == strs[3]) {
d++;
}
}
int max = Math.max(a, b);
max = Math.max(max, c);
max = Math.max(max, d);
int min = Math.min(a, b);
min = Math.min(min, c);
min = Math.min(min, d);
int distence = max - min;
if (distence == 3) {
return strs[0];
} else if (distence == 2) {
return strs[1];
} else if (distence == 4) {
return strs[2];
} else if (distence == 1) {
return strs[3];
} else {
return "F";
}
}
}
网友评论