1148 Werewolf - Simple Version (20 分)

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

题目大意:狼人杀里有狼人和村民,假设在一群人中一共有两个狼人,并且至少有一个狼人但并不是所有的狼人都说慌,而且恰好有两个说谎的人,那么你需要找出狼人。如果解不唯一,输出序号小的一组。

//当时考试的时候看着道题目,完全不理解,看了20分钟就放弃了,也是通过率最低的一道题目

//看柳神的题解,说是水题,我奔溃了。

代码来自:https://www.liuchuo.net/archives/6494 

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n+);
for (int i = ; i <= n; i++) cin >> v[i]; for (int i = ; i <= n; i++) {
for (int j = i + ; j <= n; j++) {
vector<int> lie, a(n + , );//都赋值为1.
a[i] = a[j] = -;//如果这两者是狼人。
for (int k = ; k <= n; k++)
if (v[k] * a[abs(v[k])] < ) lie.push_back(k);
//<0,则表示K在说谎。
if (lie.size() == && a[lie[]] + a[lie[]] == ) {
cout << i << " " << j;//两者都不是狼人。
return ;//直接返回,就是最小的标号
}
}
}
cout << "No Solution";
return ;
}

//这个判断<0,简直不要太厉害了。

1.v[i]表示i说v[i]是什么;

2.使用符号来判断是否说谎;

3.a[abs(v[k])]的符号用来判断当前假定条件下(a[i]和a[j]是狼人),v[k]是当前第k个人说v[k]是村民还是狼人,符号来表示,如果两者不一致,那么在此种假设下,就是说谎;

4.对于说谎的,如果长度正好为2,并且一个是狼人一个是村民,也就是二者的和为0,正负抵消。

PAT 1148 Werewolf - Simple Version [难理解]的更多相关文章

  1. PAT 1148 Werewolf - Simple Version

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

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

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

  3. PAT A1148 Werewolf - Simple Version (20 分)——暴力遍历,负负得正

    Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...

  4. 1148 Werewolf - Simple Version (20 分)

    Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...

  5. 1148 Werewolf - Simple Version

    Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...

  6. PAT_A1148#Werewolf - Simple Version

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

  7. K8S核心概念之SVC(易混淆难理解知识点总结)

    本文将结合实际工作当中遇到的一些问题和情况来解析SVC的作用以及一些比较易混淆和难理解的概念,方便日后工作用到或者遗忘时可以直接在自己曾经学习总结的博客当中直接查找到. 首先应该清楚SVC的作用是什么 ...

  8. PAT 1056 Mice and Rice[难][不理解]

    1056 Mice and Rice(25 分) Mice and Rice is the name of a programming contest in which each programmer ...

  9. 认为C/C++很难理解、找工作面试笔试,快看看这本书!

    假设你是C/C++谁刚开始学习,看这本书.因为也许你读其他的书还不如不看.一定要选择一本好书. 假设你正在准备工作,请认真看这本书,由于这本书会教会你工作中必备的知识,相信你即将面临的语法类题目不会超 ...

随机推荐

  1. JQuery EasyUI DataGrid动态合并(标题)单元) 一

    JS: /** * EasyUI DataGrid根据字段动态合并单元格 * @param fldList 要合并table的id * @param fldList 要合并的列,用逗号分隔(例如:&q ...

  2. php 显示一个干净的,易被解析的json

    header("Content-type: text/html; charset=utf-8"); //试着从数据库里读取一条数据放进来 $con = mysql_connect( ...

  3. html -- contenteditable 属性:指定元素内容是否可编辑

    所有主流浏览器都支持 contenteditable 属性 定义和用法 contenteditable 属性指定元素内容是否可编辑. 注意: 当元素中没有设置 contenteditable 属性时, ...

  4. 《linux系统及其编程》实验课记录(五)

    实验 5:权限的设置和更改 实验环境: 安装了 Red Hat Enterprise Linux 6.0 可运行系统,并且是成功验证系统.有另外一个无特权用户 student,密码 student 的 ...

  5. python中paramiko的安装

    windows下安装并使用Python的SSH模块(paramiko+pycrypto+ecdsa) 2014-01-20 14:59 2223人阅读 评论(0) 收藏 举报 python+opens ...

  6. 线程本地变更,即ThreadLocal-->Spring事务管理

    我们知道Spring通过各种模板类降低了开发者使用各种数据持久技术的难度.这些模板类都是线程安全的,也就是说,多个DAO可以复用同一个模板实例而不会发生冲突.我们使用模板类访问底层数据,根据持久化技术 ...

  7. php7 宏杂记

    php.h                                 zend_api.h ZEND_FN(name) ---> zif_##name PHP_FUNCTION(name) ...

  8. web.xml 中 classpath 写法说明

    简单理解,classpath就是代表  /WEB-INF /classes/  这个路径(如果不理解该路径,就把一个web工程发布为war包,然后用winrar查看其包内路径就理解啦) 常用的场景: ...

  9. .Net CCNet C#6.0 自动化编译问题解决

    一.问题描述 由于C#6.0一些新的语法特性,导致先前部署的CCNet持续集成平台出现问题,无论是手动还是命令行均不能编译.   二.解决方案 1.下载BuildTools_Full.exe,地址:h ...

  10. Proxool线程池的简单实现demo

    使用的jar包:ojdbc14.jar    proxool-0.9.0.jar   commons-logging-1.1.3.jar 代码分为两部分: ProxoolTest.java和proxo ...