Skip to content

Instantly share code, notes, and snippets.

@michaelHL
Created March 21, 2018 08:34
Show Gist options
  • Save michaelHL/47aa4a52888e66da57351418e4a99514 to your computer and use it in GitHub Desktop.
Save michaelHL/47aa4a52888e66da57351418e4a99514 to your computer and use it in GitHub Desktop.
/**
* 2018 年刑侦科推理试题
*
* 1. 这道题的答案是:
* A. A B. B C. C D. D
*
* 2. 第 5 题的答案是:
* A. C B. D C. A D. B
*
* 3. 以下选项中哪一题的答案与其它三项不同:
* A. 第3题 B. 第6题 C. 第2题 D. 第4题
*
* 4. 以下选项中哪两题的答案相同:
* A. 第1,5题 B. 第2,7题 C. 第1,9题 D. 第6,10题
*
* 5. 以下选项中哪一题的答案与本题相同:
* A. 第8题 B. 第4题 C. 第9题 D. 第7题
*
* 6. 以下选项中哪两题的答案与第8题相同:
* A. 第2,4@题目 B. 第1,6题 C. 第3,10题 D. 第5,9题
*
* 7. 在此十道题中, 被选中次数最少的选项字母为:
* A. C B. B C. A D. D
*
* 8. 以下选项中哪一题的答案与第1题的答案在字母中不相邻:
* A. 第7@题目 B. 第5题目 C. 第2题 D. 第10题
*
* 9. 已知「第1题与第6题的答案相同」与「第X题与第5题的答案相同」的真假性相反,
* 那么X为:
* A. 第6题 B. 第10题 C. 第2题 D. 第9题
*
* 10. 在此10道题中, ABCD 四个字母出现次数最多与最少者之差为:
* A. 3 B. 2 C. 4 D. 1
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
// anstb: 10 个题的答案(0, 1, 2, 3), 第一题下标为 1, 弃用 0 下标
// chstb: 答案频数表, 比如 {4, 3, 2, 1} 表示 4 个 A, 3 个 B, 等等
int anstb[11];
int chstb[4];
// 获得模拟题解的数字的第 digit 题答案 (0, 1, 2, 3)
// 比如数字为 139810, 二进制为 0010 0010 0010 0010 0010,
// 那么说明偶数题答案为 0, 奇数题为 2 (也就是 C)
unsigned int titans(unsigned int n, unsigned int digit) {
return (n << (16 - digit) * 2) >> 30;
}
// 将当前数字转为题解
void setans(unsigned int n) {
for (unsigned int i = 1; i <= 10; i++)
anstb[i] = titans(n, i);
}
// 将题解转为频数表
void setchoice() {
memset(chstb, 0, sizeof(chstb));
for (int i = 0; i < 10; i++)
chstb[anstb[i]] += 1;
}
bool tit_02() {
int trans[] = {2, 3, 0, 1};
return anstb[5] == trans[anstb[2]];
}
bool tit_03() {
switch (anstb[3]) {
case 0:
return anstb[6] == anstb[2] &&
anstb[2] == anstb[4] &&
anstb[4] != anstb[3];
case 1:
return anstb[3] == anstb[2] &&
anstb[2] == anstb[4] &&
anstb[4] != anstb[6];
case 2:
return anstb[3] == anstb[6] &&
anstb[6] == anstb[4] &&
anstb[4] != anstb[2];
case 3:
return anstb[3] == anstb[6] &&
anstb[6] == anstb[2] &&
anstb[2] != anstb[4];
default:
return false;
}
}
bool tit_04() {
switch (anstb[4]) {
case 0: return anstb[1] == anstb[5];
case 1: return anstb[2] == anstb[7];
case 2: return anstb[1] == anstb[9];
case 3: return anstb[6] == anstb[10];
default: return false;
}
}
bool tit_05() {
int trans[] = {8, 4, 9, 7};
return anstb[5] == anstb[trans[anstb[5]]];
}
bool tit_06() {
switch (anstb[6]) {
case 0: return anstb[2] == anstb[4] && anstb[4] == anstb[8];
case 1: return anstb[1] == anstb[6] && anstb[6] == anstb[8];
case 2: return anstb[3] == anstb[10] && anstb[10] == anstb[8];
case 3: return anstb[5] == anstb[9] && anstb[9] == anstb[8];
default: return false;
}
}
bool tit_07() {
int trans[] = {2, 1, 0, 3};
return trans[anstb[7]] == std::min_element(chstb, chstb + 4) - chstb;
}
bool tit_08() {
int trans[] = {7, 5, 2, 10};
return abs(anstb[trans[anstb[8]]] - anstb[1]) != 1;
}
bool tit_09() {
int trans[] = {6, 10, 2, 9};
bool jud1 = anstb[1] == anstb[6];
bool jud2 = anstb[trans[anstb[9]]] == anstb[5];
return jud1 != jud2;
}
bool tit_10() {
int trans[] = {3, 2, 4, 1};
int choicemax = *std::max_element(chstb, chstb + 4);
int choicemin = *std::min_element(chstb, chstb + 4);
return trans[anstb[10]] == (choicemax - choicemin);
}
void printchoice() {
int trans[] = {'A', 'B', 'C', 'D'};
for (int i = 0; i < 10; i++)
printf("%s%c", i ? " " : "", trans[anstb[i + 1]]);
puts("");
}
int main() {
for (unsigned int t = 0x0; t <= 0xfffff; t++) {
setans(t);
setchoice();
if (tit_02() && tit_03() && tit_04() && tit_05() &&
tit_06() && tit_07() && tit_08() && tit_09() && tit_10()) {
printchoice();
break;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment