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

狼人杀简单版

1. 原文

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.

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≤iN), 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] (ik) 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
2
3
4
5
6
5
-2
+3
-4
+5
+4

Sample output:

1
1 4

Sample Input 2:

1
2
3
4
5
6
7
6
+6
+3
+1
-5
-2
+4

Sample output:

1
1 5

Sample Input:

1
2
3
4
5
6
5
-2
-3
-4
-5
-1

Sample output:

1
No Solution

2. 解析

不要想太深!

🧷固定狼人🐺i,🐺j ,循环遍历每个人k说的话say[k]:

  • 当他说 say[k]<0 为狼人,但say[k]并不是狼人 i,狼人 j –> k说谎
  • 当他说 say[k]>0 为平民,但say[k]是狼人 i 或 狼人 j –> k说谎

最后统计

当k不是狼人i 或 j 但他说了谎 –> 平民说谎

否则 –> 狼人说话

3. AC代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<cstdio>
#include<algorithm>
using namespace std;
int say[110]={};
int main()
{
int n;
scanf("%d",&n);
for (int i = 1; i <= n; ++i)
{
scanf("%d",&say[i]);
}
int wolf1=0;int wolf2=0;
for (int i = 1; i <= n; ++i)
{
for (int j = i+1; j <= n; ++j)
{
int human=0;
int wolf=0;
for (int k = 1; k <= n; ++k)
{
if ((say[k]<0&&abs(say[k])!=i&&abs(say[k])!=j)||
((say[k]>0)&&(say[k]==i||say[k]==j)))
{
if (k!=i&&k!=j)
{
human++;
}
else{
wolf++;
}
}
}
if (human==1&&wolf==1)
{
wolf1=i;
wolf2=j;
break;
}
}
if (wolf1!=0)
{
break;
}
}
if (wolf1!=0)
{
printf("%d %d\n",wolf1,wolf2);
}else{
printf("No Solution\n");
}
return 0;
}
本文结束  感谢您的阅读
  • 本文作者: Wang Ting
  • 本文链接: /zh-CN/2019/09/02/A1148/
  • 发布时间: 2019-09-02 13:45
  • 更新时间: 2021-10-29 14:11
  • 版权声明: 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!