目录

题目

Input Specification:

Output Specification:

Sample Input 1:

Sample Output 1:

Sample Input 2:

Sample Output 2 (the solution is not unique):

Sample Input 3:

Sample Output 3:

思路

代码


题目

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

思路

难度评级:⭐️⭐️⭐️⭐️

难度评四颗星的原因是,我拿到这题时一点思路也没有,不知道如何下手,看了PAT 1148 Werewolf  柳婼 の blog的代码才知道其实是枚举每一种狼人情况的方法,并且柳神非常巧妙地运用了正负数乘积为负数这一点作为一些 if 的判断,非常值得学习借鉴。

代码

#include <iostream>
#include <vector>
#include <algorithm>using namespace std;int main(int argc, char** argv) {int n;cin>>n;vector<int> words(n+1);for(int i=1;i<=n;i++) cin>>words[i];// 枚举每一种狼人情况 for(int i=1;i<n;i++) {for(int j=i+1;j<=n;j++) {vector<int> identity(n+1, 1);// 标识每个人的身份,1表示村民,-1表示狼人 vector<int> liars; // 假设用户i和用户j为狼人identity[i]=-1;identity[j]=-1;// 遍历每个人说的话,判断他是否说谎 for(int k=1;k<=n;k++) {if(words[k]*identity[abs(words[k])]<0) {liars.push_back(k);}}// 检查说谎的人是否有两个人,且一个是狼人一个村民if(liars.size()==2&&identity[liars[0]]*identity[liars[1]]<0) {cout<<i<<" "<<j;return 0;} }}cout<<"No Solution";return 0;
}

【PTA Advanced】1148 Werewolf - Simple Version(C++)相关推荐

  1. 【PAT甲级题解记录】1148 Werewolf - Simple Version (20 分)

    [PAT甲级题解记录]1148 Werewolf - Simple Version (20 分) 前言 Problem:1148 Werewolf - Simple Version (20 分) Ta ...

  2. 1148 Werewolf - Simple Version (20 分)

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

  3. 【AAAI 2020】全部接受论文列表(三)

    来源:AINLPer微信公众号(点击了解一下吧) 编辑: ShuYini 校稿: ShuYini 时间: 2020-01-22 最近武汉肺炎形势严峻,请小伙伴们带好口罩,做好防护,大家新年快乐~    ...

  4. 【AAAI 2020】全部接受论文列表(四)

    来源:AINLPer微信公众号(点击了解一下吧) 编辑: ShuYini 校稿: ShuYini 时间: 2020-01-22 最近武汉肺炎形势严峻,请小伙伴们带好口罩,做好防护,大家新年快乐~    ...

  5. 【AAAI 2020】全部接受论文列表(二)

    来源:AINLPer微信公众号(点击了解一下吧) 编辑: ShuYini 校稿: ShuYini 时间: 2020-01-22 最近武汉肺炎形势严峻,请小伙伴们带好口罩,做好防护,大家新年快乐~    ...

  6. 是男人就下100层【第一层】——高仿微信界面(4)

    上一篇<是男人就下100层[第一层]--高仿微信界面(3)>中我们完成了登录,这一篇看完成登录后的一个短暂加载和引导界面. 加载界面: <RelativeLayout xmlns:a ...

  7. 【自动驾驶】高级驾驶辅助系统(ADAS)

    [自动驾驶]高级驾驶辅助系统(ADAS) 参考 技术起底 | 高级驾驶辅助系统(ADAS) - 知乎 (zhihu.com) 详解智能汽车高级辅助驾驶系统:抬头显示.自适应巡航.碰撞预警.自动泊车 文 ...

  8. 【AAAI 2021】全部接受论文列表(五)

    来源:AINLPer微信公众号(点击了解一下吧) 编辑: ShuYini 校稿: ShuYini 时间: 2021-01-14 马上春节了,疫情又卷土而来,希望大家注意防护,爱护自己的身体 AAAI ...

  9. 【Java基础】swing-图形界面学习(下)

    就是个人学习的笔记,按照下面的Demo一个一个复制粘贴跑起来大概就会使用Swing了,建议先从上半部分开始看 上半部分 [Java基础]swing-图形界面学习(上) 八.菜单 GUI的菜单分为 菜单 ...

最新文章

  1. 怎样实现两个线程共享一个集合_面试高频考察点:几种线程安全的Map解析
  2. Ant基础介绍(转载)
  3. java--面向对象(4)--黑马程序员
  4. 使用 gitlab 进行代码管理
  5. 数据改动,更新视图,类似于vue
  6. 遍历聚合对象中的元素——迭代器模式
  7. 重学前端学习笔记(八)--JavaScript中的原型和类
  8. 解决 idea 复制jsp 文件过来页面报404
  9. Solving environment: failed with initial frozen solve.Retrying with flexible solve
  10. 95-36-110-ChannelHandler-ChannelDuplexHandler
  11. python创建树_python – 从SQLalchemy中的自引用表创建树
  12. centos部署k8s集群(kubeadm方式)
  13. 无卡支付系统(德齐互联)
  14. 手机java系统说明什么_Android的手机系统是开源的,开源到底是什么意思?
  15. drill down roll up
  16. linux版本市场占有率,2020年5月OS市场占有率报告:Ubuntu和Linux分别占有1.89%和0.97%...
  17. VMware虚拟机扩容——Ubuntu的/dev/sda1分区挂在根目录(“/“)下用LVM(逻辑卷管理)模式扩容无效
  18. ping回显无法访问目标网络network unreachable故障模拟
  19. Java+MySQL 基于ssm的停车位短租租赁管理系统程序#毕业设计
  20. python如何制作脚本_用python给自己做一款小说阅读器过程详解

热门文章

  1. JS经典面试题:JS原型、原型链
  2. android 环信消息撤回
  3. ctf xss利用_TCTF/0CTF2018 XSS Writeup
  4. down 网卡端口周期性的up_思科沟通机端口down或up缺陷要素
  5. 计算机弹奏爱情码头,转发人事部关于全国专业技术人员计算机应用能力考试的通知...
  6. HTML5 画布 火柴人实例及代码
  7. 新闻稿怎么发,小编告诉你
  8. archlinux 安装笔记
  9. 项目管理之项目合同变更
  10. 好用的国产远程控制软件,我只推荐这款!