蓝桥杯 ADV-124 算法提高 凶手

算法提高 凶手

时间限制:1.0s 内存限制:256.0MB

 

问题描述
  巴斯维克命案抓住了六个嫌疑犯,他们的口供如下:
  A:我不是罪犯
  B:A、C中有一个是罪犯
  C:A和B说了假话
  D:C和F说了假话
  E:其他五个人中,只有A和D说了真话
  F:我是罪犯
  他们中只有一半说了真话,凶手只有一个。
  本题可能有多种可能性,即正确答案(找到唯一的凶手)可能有多个,但每一个可能的答案(某一个是凶手)都满足上述口供。
  请编程找出可能的凶手输出。
  样例:(假设唯一的凶手是A或者D或者E,则输出结果为三行,按字母顺序依次输出)
  A
  D
  E
 

#include <stdio.h>

int main()
{
    int murderer[6] = { 0 };

    for (int i = 0; i < 6; ++i)
    {
        int is_truth[6] = { 0 };
        int num_truth = 0;
        murderer[i] = 1;

        if (!murderer[0])
            is_truth[0] = 1;
        if (murderer[0] || murderer[2])
            is_truth[1] = 1;
        if (!is_truth[0] && !is_truth[1])
            is_truth[2] = 1;
        if (murderer[5])
            is_truth[5] = 1;
        if (!is_truth[2] && !is_truth[5])
            is_truth[3] = 1;
        if (is_truth[0] && is_truth[3] && !is_truth[1] && !is_truth[2] && !is_truth[5])
            is_truth[4] = 1;

        for (int j = 0; j < 6; ++j)
            if (is_truth[j])
                num_truth++;
        if (num_truth == 3)
            printf("%c\n", 'A' + i);

        murderer[i] = 0;
    }

    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值