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). Then Nlines follow and the i-th line gives the statement of the i-th player (1), 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 [ and [, if there exists 0 such that [ (i≤k) and [, then A is said to be smaller than B. In case there is no solution, simply print No Solution.

Sample Input 1:

5
-2
+3
-4
+5
+4

Sample Output 1:

1 4

Sample Input 2:

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

Sample Output 2 (the solution is not unique):

1 5

Sample Input 3:

5
-2
-3
-4
-5
-1

Sample Output 3:

No Solution

Solution:

  mmp,看了半天题目,以为要用一个复杂算法来推导,半天想不出来,后来才发现,20分的题,你千万不要看高了他,该暴力就暴力,该遍历就遍历,不要想用什么高大上的算法!!!

  这道题就是使用暴力遍历,从1开始,每两个个人假设为狼人,然后去验证几个人说谎了,并且是不是一个好人和一个狼人说谎了,对,就这么简单,就他妈的用遍历!!!

  

 #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int>speak(n + ), name(n + , );
for (int i = ; i <= n; ++i)cin >> speak[i];
for (int i = ; i <= n; ++i)//假设i,j是狼人
{
for (int j = i + ; j <= n; ++j)
{
vector<int>lie, v(n + , );//都是好人
v[i] = v[j] = -;//标记狼人
for (int t = ; t <= n; ++t)
if (v[abs(speak[t])] * speak[t] < )//说是好人,但实际是狼人,他说谎了
lie.push_back(t);
if (lie.size() == && v[lie[]] + v[lie[]] == )//一个好人撒谎,一个坏人撒谎
{
cout << i << " " << j << endl;
return ;
}
}
}
cout << "No Solution" << endl;
return ;
}

PAT甲级——A1148 WerewolfSimpleVersion【20】的更多相关文章

  1. PAT 甲级 1035 Password (20 分)(简单题)

    1035 Password (20 分)   To prepare for PAT, the judge sometimes has to generate random passwords for ...

  2. PAT甲级——1035 Password (20分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  3. PAT 甲级 1008 Elevator (20)(代码)

    1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...

  4. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  5. PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)

    1061 Dating (20 分)   Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...

  6. PAT 甲级 1008 Elevator (20)(20 分)模拟水题

    题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...

  7. PAT甲级——1061 Dating (20分)

    Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkg ...

  8. PAT甲级——1005.SpellItRight(20分)

    Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...

  9. PAT甲级——1077.Kuchiguse(20分)

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

随机推荐

  1. git push github 免输入账号和密码方法

    git config --global credential.helper store 打开~/.gitconfig文件,会发现多了一项: [credential] helper = store 此时 ...

  2. Django--Aadmin入门

  3. Java-技术专区-如何监控Java线程池的状态

    线程池介绍 什么是线程池.线程池核心类.线程池工作流程.线程池分类.拒绝策略.及如何提交与关闭线程池等. 但在实际开发过程中,在线程池使用过程中可能会遇到各方面的故障,如线程池阻塞,无法提交新任务等. ...

  4. elementUI table宽度自适应fit

    :fit='true' 或者直接为 fit

  5. c# HttpListener 使用

    与 IIS 上发布网站相比,使用 HttpListener 编程的程序更加轻量化,易于发布和更新.配合 Thread 或 Task 类也可满足一定的并发. https://docs.microsoft ...

  6. C#break和continue学习

    一,代码 static void Main(string[] args) { ; while (true) { int num = Convert.ToInt32(Console.ReadLine() ...

  7. db2中将表中的某一字段设置为自增长

    DB2可以使用generated always as identity 将某一个字段指定为自增长的字段: 这表示id自动是一个自增长的字段,它从1开始增加每次增加1.也可以通过generated 将字 ...

  8. 五、通过密码访问API

    通过密码访问API 一.客户端 图: 客户端请求代码: static void Main(string[] args) { Console.WriteLine("确定三个项目都已经启动&qu ...

  9. Linux系统测试端口连通性的方法

    Linux系统测试端口连通性的方法 有四种常用方法:1. telnet 方法2. wget 方法3. ssh 方法4. curl 方法 下面一一介绍. 1. telnet用法: telnet ip p ...

  10. wireshark简单的过滤条件

    http://blog.csdn.net/blue_jjw/article/details/8467885 一.IP过滤:包括来源IP或者目标IP等于某个IP比如:ip.src addr==192.1 ...