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:

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

Sample Output 1:

  1. 1 4

Sample Input 2:

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

Sample Output 2 (the solution is not unique):

  1. 1 5

Sample Input 3:

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

Sample Output 3:

  1. No Solution
  2.  
  3. Solution

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

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

  

  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7. int n;
  8. cin >> n;
  9. vector<int>speak(n + ), name(n + , );
  10. for (int i = ; i <= n; ++i)cin >> speak[i];
  11. for (int i = ; i <= n; ++i)//假设i,j是狼人
  12. {
  13. for (int j = i + ; j <= n; ++j)
  14. {
  15. vector<int>lie, v(n + , );//都是好人
  16. v[i] = v[j] = -;//标记狼人
  17. for (int t = ; t <= n; ++t)
  18. if (v[abs(speak[t])] * speak[t] < )//说是好人,但实际是狼人,他说谎了
  19. lie.push_back(t);
  20. if (lie.size() == && v[lie[]] + v[lie[]] == )//一个好人撒谎,一个坏人撒谎
  21. {
  22. cout << i << " " << j << endl;
  23. return ;
  24. }
  25. }
  26. }
  27. cout << "No Solution" << endl;
  28. return ;
  29. }

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. python中6个序列的内置类型分别是什么,列表和元组的异同有哪些

    1.Python中6个序列的内置类型分别是什么? Python包含6中内建的序列,即列表.元组.字符串.Unicode字符串.buffer对象和 xrange 对象.序列通用的操作包括:索引.长度.组 ...

  2. VC6.0在Win8,10下的兼容性调整

    Microsoft Visual C++ 6.0,简称VC6.0,是微软推出的一款C++编译器,将“高级语言”翻译为“机器语言(低级语言)”的程 序.Visual C++是一个功能强大的可视化软件开发 ...

  3. txt文本程序 打开python文件 另存为原来的文件名,不能覆盖原来的文件解决

    txt文本程序 打开python文件 另存为原来的文件名,不能覆盖原来的文件 如:1.py文件用txt文本程序打开后,另存为 1.py,保存完毕后,不覆盖1.py文件,会生成 1.py.txt文件 原 ...

  4. 第五节 RabbitMQ在C#端的应用-消息收发

    原文:第五节 RabbitMQ在C#端的应用-消息收发 版权声明:未经本人同意,不得转载该文章,谢谢 https://blog.csdn.net/phocus1/article/details/873 ...

  5. ps学习记录

    基本快捷键: ctrl + 放大 ctrl - 缩小 ctrl 空格键 放大工具 ctrl 0 适合屏幕大小 ctrl 1 显示实际大小 ctrl n 新建画布 ctrl v 移动工具 按住alt键 ...

  6. css行高的用法总结

    css没有提供一个直接设置行间距的方式,所以只能通过设置行高来间接的设置行间距,行高越大行间距就越大,用 line-height 来设置行高. .p1 { /* 设置行高 */ line-height ...

  7. Ubuntu 16.04 修改状态栏位置

    修改状态栏位置: gsettings set com.canonical.Unity.Launcher launcher-position Bottom #底部(苹果风格) gsettings set ...

  8. js使用childnodes获取子节点时多了text节点

    当我们获取标签的节点时如果使用childnodes发现它会把空格和回车都算着节点,明明里面才有3个节点,结果显示5个,而且childnodes[0]="text" 在IE浏览器中没 ...

  9. 关于计算机与MCU通信及MAX232、CH340T与PL2303的区别

    原理:单片机的TXD.RXD是TTL电平,所以你得万变不离其宗的将其它信号转成TTL电平,只有这样给单片机下载程序才有可能成功!其中CH340.PL2303等芯片是直接将USB信号转换为TTL电平或者 ...

  10. python3 实现堡垒机功能(并发执行命令及上传下载文件)

    转载请注明出处,欢迎提出宝贵意见,谢谢! 功能介绍: 1.主机分组 登录后显示分组主机及主机数量 选择主机组后显示该主机组下所有主机信息,主机名及IP显示输入选择:1.执行命令利用线程并发组内所有主机 ...