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:

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

#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <set>
#include <vector>
using namespace std;
const int maxn=;
int wolf[maxn];
int state[maxn];
struct node{
int w[];
};
bool cmp(node n1,node n2){
return n1.w[]==n2.w[]?n1.w[]<n2.w[]:n1.w[]<n2.w[];
}
vector<node> v;
int main(){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++){
int tmp;
scanf("%d",&tmp);
state[i]=tmp;
}
int i,j,flag=;
for(i=;i<n;i++){
for(j=i+;j<=n;j++){
fill(wolf,wolf+maxn,);
wolf[i]=-;
wolf[j]=-;
int cnt=;
for(int k=;k<=n;k++){
if(wolf[abs(state[k])]*state[k]<){
cnt++;
}
}
if(cnt!=) continue;
else{
if(wolf[abs(state[i])]*state[i]*wolf[abs(state[j])]*state[j]<){
printf("%d %d",i,j);
return ;
}
}
}
}
printf("No Solution");
}

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

因此这题需要设置两个狼人,然后判断是不是两个人说谎,并且是一狼一人。看了大佬的思路才发现判断是不是说谎只要看这个人的陈述和这个人说的人的真实身份乘起来是不是小于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. SSM+solr 通过商品搜索学习solr的简单使用

    学习了一下https://github.com/TyCoding/ssm-redis-solr这个github上的solr搜索功能,现在来记录一下. 我的理解就是solr有点类似于数据库,但它是有索引 ...

  2. tomcat8 manager页面限制IP访问

    tomcat8 manager页面限制IP访问 配置tomcat8/webapps/manager/META-INF/context.xml <Context antiResourceLocki ...

  3. PHP7.27: connect mysql 5.7 using new mysqli_connect

    <!doctype html> <html> <head> <meta name="viewport" content="wid ...

  4. 【读书笔记】iOS-个人开发者与企业开发者的区别

    个人开发者与企业开发者的一个主要的区别在于独立开发者授权描述文件必须列出具体的设备.另一个不同就是开发者账户最多使用100台设备,而企业则可以让苹果公司生成未锁定到特定设备并可以安装到任何设备上的授权 ...

  5. ubuntu18.04突然无法上网解决方法

    sudo service network-manager stop sudo rm /var/lib/NetworkManager/NetworkManager.state sudo service ...

  6. weblogic系列漏洞整理 -- 1. weblogic安装

    目录 0. 概述 1. 下载安装Java环境 2. 下载安装weblogic 安装 部署domain域 进入weblogic 3. 排错 如果出现如下错误 0. 概述 WebLogic是美国Oracl ...

  7. (转载)Oracle 树操作(select…start with…connect by…prior)

    转载地址:https://www.cnblogs.com/linjiqin/p/3152674.html 备注:如有侵权,请立即联系删除. oracle树查询的最重要的就是select…start w ...

  8. EntityFramework Code-First 简易教程(七)-------领域类配置之Fluent API

    Fluent API配置: 前面我们已经了解到使用DataAnotations特性来覆写Code-First默认约定,现在我们来学习Fluent API. Fluent API是另一种配置领域类的方法 ...

  9. JVM虚拟机查找类文件的顺序

    JVM查找类文件的顺序: 在doc下使用set classpath=xxx, 如果没有配置classpath环境变量,JVM只在当前目录下查找要运行的类文件. 如果配置了classpath环境,JVM ...

  10. Java设计模式之三 ----- 建造者模式和原型模式

    前言 在上一篇中我们学习了工厂模式,介绍了简单工厂模式.工厂方法和抽象工厂模式.本篇则介绍设计模式中属于创建型模式的建造者模式和原型模式. 建造者模式 简介 建造者模式是属于创建型模式.建造者模式使用 ...