思路:
暴力破解,验证组合 {(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";
}