T1022 Werewolf (35 point(s))

T1022 Werewolf (35 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 vertion of this problem: given that there were N players, with M werewolves among them, at least one but not all the werewolves were lying, and there were exactly L 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 three positive integer N (5 ≤ N ≤ 100), M and L (2 ≤ M,L < N). 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 descending order the indices of the M 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 largest 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 larger than B. In case there is no solution, simply print No Solution.

Sample Input 1:

5 2 2
-2
+3
-4
+5
+4

Sample Output 1:

4 1

Sample Input 2:

6 2 3
-2
+3
-4
+5
+4
-3

Sample Output 2:

6 4

Sample Input 3:

6 2 5
-2
+3
-4
+5
+4
+6

Sample Output 3:

No Solution

题目限制条件

  • 时间限制:100ms
  • 内存限制:64MB

题目大意

N名玩家坐在一起玩狼人杀(编号为1到N),其中有M人是狼人。现在给出某一轮各玩家的发言,每名玩家都会声称在场某玩家的身份是好人(用"+"表示)或狼人(用"-"表示)。已知此轮发言中恰好有L人说谎(其发言与事实不符),且至少有一名狼人说谎但并非所有狼人都说谎。请判断哪些玩家是狼人,降序输出他们的编号。如果有多解,输出最大序列解;如果无解,输出No Solution

本题考察知识点

  • 深度优先搜索(Depth First Search, DFS)

解题思路

本题与 A1148 如出一辙,只是要考虑的因素变多了:多了狼人数说谎人数这两个参数。但这两题的思路都是一样的:DFS列举所有可能的狼人组合,然后分别判断每个组合的合法性(是否符合题目要求)。

判断合法性的过程如下:

  1. 遍历一遍所有人说过的话,并根据目前的狼人组合筛选出说谎的玩家。
  2. 判断说谎玩家数量是否为L。
  3. 判断说谎的狼人数量是否在[1,M)范围内。

由于题目要求输出最大序列解</

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值