1148 Werewolf - Simple Version (20 point(s))

思路:

暴力破解,验证组合 {(i, j) |  1<=i<j<=N},是否满足给定条件:

1个狼人说谎,另外一个狼人不说谎,还有1个平民说谎(at least one but not all the werewolves were lying)

组合 (i,j)就是解,没有就是无解。

1148 Werewolf - Simple Version (20 point(s))

Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game,

  • player #1 said: "Player #2 is a werewolf.";
  • player #2 said: "Player #3 is a human.";
  • player #3 said: "Player #4 is a werewolf.";
  • player #4 said: "Player #5 is a human."; and
  • player #5 said: "Player #4 is a human.".

Given that there were 2 werewolves among them, at least one but not all the werewolves were lying, and there were exactly 2 liars. Can you point out the werewolves?

Now you are asked to solve a harder version of this problem: given that there were N players, with 2 werewolves among them, at least one but not all the werewolves were lying, and there were exactly 2 liars. You are supposed to point out the werewolves.

Example:

#include<iostream>
#include<cmath>
#include<vector>
#include<set>
using namespace std;

int main()
{
    int  N;
    cin >> N;
    vector<int> player(N+1);
    for(int i = 1; i <= N; i++) cin >> player[i];
    vector<int> real(N+1, 1);
    for(int i = 1; i <= N-1; i++) {
        real[i] = -1;
        for(int j = i+1; j <= N; j++) {
            set<int> lies;
            lies.clear();
            real[j] = -1;
            for(int k = 1; k <= N; k++) 
                if(real[abs(player[k])] * player[k] < 0) lies.insert(k);
            if(lies.size() == 2 && (lies.count(i) + lies.count(j) == 1)) {
                cout << i << ' ' << j;
                return 0;
            }
            real[j] = 1;
        }
        real[i] = 1;
    }
    cout << "No Solution";
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值