题目链接:点击这里
只有一半人说了真话,凶手只有一个。
一种思路是,枚举三个说真话的人,然后判断凶手是否唯一,最终按字母顺序依次输出。
逆向考虑更简单,假设每个人都可能是凶手,依次枚举,然后判断是否有三个命题为真。
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const int MOD = 10000007;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int maxn = 10;
int a[10];
bool check()
{
int cnt = 0;
bool flaga = false;
if(a[1]==0) //A真
{
flaga = true;
cnt++;
}
bool flagb = false;
if((a[1]==1&&a[3]==0)||(a[1]==0&&a[3]==1)) //B真
{
flagb = true;
cnt++;
}
bool flagf = false;
if(a[6]==1) //F真
{
flagf = true;
cnt++;
}
bool flagc = false;
if(!flaga&&!flagb) //C真
{
flagc = true;
cnt++;
}
bool flagd = false;
if(!flagc&&!flagf) //D真
{
flagd = true;
cnt++;
}
bool flage = false;
if(flaga && flagd && !flagb && !flagc && !flagf) //E真
{
flage = true;
cnt++;
}
if(cnt==3) return true;
else return false;
}
int main()
{
for(int i = 1; i <= 6; ++i)
{
memset(a, 0, sizeof(a));
a[i] = 1;
if(check())
printf("%c\n", 'A'+i-1);
}
return 0;
}