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≤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
  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

  1. #include <stdio.h>
  2. #include <algorithm>
  3. #include <string.h>
  4. #include <set>
  5. #include <vector>
  6. using namespace std;
  7. const int maxn=;
  8. int wolf[maxn];
  9. int state[maxn];
  10. struct node{
  11. int w[];
  12. };
  13. bool cmp(node n1,node n2){
  14. return n1.w[]==n2.w[]?n1.w[]<n2.w[]:n1.w[]<n2.w[];
  15. }
  16. vector<node> v;
  17. int main(){
  18. int n;
  19. scanf("%d",&n);
  20. for(int i=;i<=n;i++){
  21. int tmp;
  22. scanf("%d",&tmp);
  23. state[i]=tmp;
  24. }
  25. int i,j,flag=;
  26. for(i=;i<n;i++){
  27. for(j=i+;j<=n;j++){
  28. fill(wolf,wolf+maxn,);
  29. wolf[i]=-;
  30. wolf[j]=-;
  31. int cnt=;
  32. for(int k=;k<=n;k++){
  33. if(wolf[abs(state[k])]*state[k]<){
  34. cnt++;
  35. }
  36. }
  37. if(cnt!=) continue;
  38. else{
  39. if(wolf[abs(state[i])]*state[i]*wolf[abs(state[j])]*state[j]<){
  40. printf("%d %d",i,j);
  41. return ;
  42. }
  43. }
  44. }
  45. }
  46. printf("No Solution");
  47. }

注意点:一开始想设置两个人说谎,然后再去判断是不是总共两个狼人一个说谎一个没有,一直有问题,分析了一下是逻辑很有问题,因为会存在有的人在陈述时会被多次点到,有的人一次都没点到,这样根据说不说谎去判断会出现很多问题,而且最后输出狼人而不是说谎的人,也会很麻烦。

因此这题需要设置两个狼人,然后判断是不是两个人说谎,并且是一狼一人。看了大佬的思路才发现判断是不是说谎只要看这个人的陈述和这个人说的人的真实身份乘起来是不是小于0,小于0就是说谎,负负得正,正负得负的思路。

PAT A1148 Werewolf - Simple Version (20 分)——暴力遍历,负负得正的更多相关文章

  1. PAT 1148 Werewolf - Simple Version

    1148 Werewolf - Simple Version (20 分)   Werewolf(狼人杀) is a game in which the players are partitioned ...

  2. PAT 1148 Werewolf - Simple Version [难理解]

    1148 Werewolf - Simple Version (20 分) Werewolf(狼人杀) is a game in which the players are partitioned i ...

  3. PAT_A1148#Werewolf - Simple Version

    Source: PAT 1148 Werewolf - Simple Version (20 分) Description: Werewolf(狼人杀) is a game in which the ...

  4. PAT(A) 1148 Werewolf - Simple Version(Java)逻辑推理

    题目链接:1148 Werewolf - Simple Version (20 point(s)) Description Werewolf(狼人杀) is a game in which the p ...

  5. PAT乙级:1088 三人行 (20分)

    PAT乙级:1088 三人行 (20分) 题干 子曰:"三人行,必有我师焉.择其善者而从之,其不善者而改之." 本题给定甲.乙.丙三个人的能力值关系为:甲的能力值确定是 2 位正整 ...

  6. PAT乙级:1064 朋友数 (20分)

    PAT乙级:1064 朋友数 (20分) 题干 如果两个整数各位数字的和是一样的,则被称为是"朋友数",而那个公共的和就是它们的"朋友证号".例如 123 和 ...

  7. PAT 甲级 1035 Password (20 分)

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

  8. pat 1108 Finding Average(20 分)

    1108 Finding Average(20 分) The basic task is simple: given N real numbers, you are supposed to calcu ...

  9. pat 1046 Shortest Distance(20 分) (线段树)

    1046 Shortest Distance(20 分) The task is really simple: given N exits on a highway which forms a sim ...

随机推荐

  1. 微信跳一跳Python辅助无需配置一键操作

    作者:NiceCui 本文谢绝转载,如需转载需征得作者本人同意,谢谢. 本文链接:http://www.cnblogs.com/NiceCui/p/8350329.html 邮箱:moyi@moyib ...

  2. linux学习笔记-安装配置使用clamav杀毒软件

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 1.安装clamav 2.更新病毒库 # freshclam 如果更新不了,或者更新特别慢,可以手动下载病毒库文件,放到/var ...

  3. CDQ分治小结

    CDQ分治小结 warning:此文仅用博主复习使用,初学者看的话后果自负.. 复习的时候才发现以前根本就没写过这种东西的总结,简单的扯一扯 cdq分治的经典应用就是解决偏序问题 比如最经典的三维偏序 ...

  4. Java字符串占位符(commons-text)替换(转载)

    Java字符串占位符(commons-text)替换 https://blog.csdn.net/varyall/article/details/83651798 <dependency> ...

  5. Python 基于python编写一些算法程序等

    基于python编写一些算法程序等 by:授客 QQ:1033553122 QQ群:7156436 没特意去研究,只是这对群友在QQ群里(7156436)提出的一些小程序实现.编程题,算法.问题等,本 ...

  6. 接口自动化 基于python+Testlink+Jenkins实现的接口自动化测试框架[V2.0改进版]

    基于python+Testlink+Jenkins实现的接口自动化测试框架[V2.0改进版]   by:授客 QQ:1033553122 由于篇幅问题,,暂且采用网盘分享的形式: 下载地址: [授客] ...

  7. 安卓开发_关于WebView加载页面空白问题

    依据我自己的测试,发现有时候用APP打开网页的时候,有的网页加载成功之前需要很久,有的一下就出来了(比如百度) 当加载时间过长的情况下,这时候显示的是空白界面,其实不是代码问题,只是要打开的这个网页太 ...

  8. Python中For循环

    1. for i in range(10): print(i) 输出结果 F:\py\pyProject\venv\Scripts\python.exe F:/py/pyProject/venv/wh ...

  9. LeetCode题解之Binary Tree Level Order Traversal II

    1.题目描述 2.题目分析 先遍历,再反转. 3.代码 vector<vector<int>> levelOrderBottom(TreeNode* root) { vecto ...

  10. 转,ffmpeg参数中文详细解释

    a) 通用选项 -L license-h 帮助-fromats 显示可用的格式,编解码的,协议的...-f fmt 强迫采用格式fmt-I filename 输入文件-y 覆盖输出文件-t durat ...