狼人杀简单版,暴力枚举
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.
Problem: PAT-A 1148 Werewolf - Simple Version
Input Specification
Each input file contains one test case. For each case, the first line gives a positive integer N (5 ≤ N ≤ 100). Then N lines follow and the i-th line gives the statement of the i-th player (1 ≤ i ≤ N), which is represented by the index of the player with a positive sign for a human and a negative sign for a werewolf.
Output Specification
If a solution exists, print in a line in ascending order the indices of the two werewolves. The numbers must be separated by exactly one space with no extra spaces at the beginning or the end of the line. If there are more than one solution, you must output the smallest solution sequence – that is, for two sequences A=a[1],…,a[M] and B=b[1],…,b[M], if there exists 0 ≤ k < M such that a[i] = b[i] (i ≤ k) and a[k+1]<b[k+1], then A is said to be smaller than B. In case there is no solution, simply print No Solution
.
Sample Input 1
1 | 5 |
Sample Output 1
1 | 1 4 |
Sample Input 2
1 | 6 |
Sample Output 2
1 | 1 5 |
Sample Input 3
1 | 5 |
Sample Output 3
1 | No Solution |
Analysis
题目划重点:
- N 个玩家中有 2 个狼人
- 至少 1 个狼人说谎
- 不是所有狼人都说谎
- 有 2 个玩家说谎
也就是说,说谎的 2 个玩家中 1 个狼人 1 个人类。题目要求输出 2 个狼人的序号,因此枚举所有可能的 2 个狼人的组合,检查该组合下的说谎玩家数及身份,如果恰为 2 个玩家说谎且 1 个狼人 1 个人类,即为所求解。
Code
1 |
|
Tsukkomi
没有读清题就开始写了,半路才发现说谎的玩家中1个狼人1个人类。想着能不能用什么巧妙的方法得出结果,无奈太笨。网上搜了搜大佬的解法才知道直接暴力枚举就 vans 了。