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

//来自liu chuo大佬的答案
#include<iostream>
#include<vector>
using namespace std;
int main(){int n;    cin >> n;vector<int> v(n+1);for(int i = 1; i <= n; i++)cin >> v[i];for(int i = 1; i <= n; i++){for(int j = i+1; j <= n; j++){vector<int> lie,a(n+1,1);a[i] = a[j] = -1;for(int k = 1; k <= n; k++)if(v[k]*a[abs(v[k])] < 0) lie.push_back(k);if(lie.size() == 2 && a[lie[0]] + a[lie[1]] == 0){cout << i << " " << j;return 0;}                 }}cout << "No Solution";return 0;
}

转载于:https://www.cnblogs.com/wanghao-boke/p/10458707.html

1148 Werewolf - Simple Version (20 分)相关推荐

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

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

  2. PAT甲级 -- 1148 Werewolf - Simple Version (20 分)

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

  3. PAT(甲级)2018年秋季考试 7-1 Werewolf - Simple Version (20 分)

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

  4. 【PTA Advanced】1148 Werewolf - Simple Version(C++)

    目录 题目 Input Specification: Output Specification: Sample Input 1: Sample Output 1: Sample Input 2: Sa ...

  5. PAT 1148 Werewolf – Simple Version – 甲级

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

  6. 1148 Werewolf - Simple Version

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

  7. 1148 Werewolf - Simple Version 甲级

    题意: 有n个玩家,有两个狼人,有两人说慌(其中一个为狼人一个为非狼人),找出狼人是谁? 题解: 暴力枚举 先枚举i和j为狼人,然后从1号开始假设其说谎,然后判断是否符合题目要求 代码: #inclu ...

  8. PAT_A1148#Werewolf - Simple Version

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

  9. 「1148」Werewolf - Simple Version

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

最新文章

  1. R语言使用ggplot2包geom_jitter()函数绘制分组(strip plot,一维散点图)带状图(改变分组次序)实战
  2. 借助混沌工程工具 ChaosBlade 构建高可用的分布式系统
  3. gitignore重要技巧
  4. unbuntu 的更新源
  5. boost::mpl模块实现same_as相关的测试程序
  6. 结合MSDN理解windows service 服务安装的三个类。
  7. python数据论文_如何利用Python绘制学术论文图表
  8. FTPClient删除linux文件夹,使用ftp读取文件夹中的多个文件,并删除
  9. #include与#include的区别
  10. 内存溢出真实案例分析
  11. 大疆aeb连拍_大疆进军运动相机领域,发布OSMO?ACTION,对标GoPro
  12. windows内核基础
  13. 全网最最最详细的软件著作权申请步骤
  14. Baumer工业相机堡盟工业相机如何联合BGAPISDK和佳能EF变焦镜头实现相机的自动变焦(C++)
  15. Unity实用案例之——动画压缩
  16. 2020年计算机竞赛姜子敬,初赛公示_2020年全国高校计算机能力挑战赛
  17. Java_scaner用法
  18. mounted钩子函数_解决Vue中mounted钩子函数获取节点高度出错问题
  19. redis第三方软件medis
  20. 中国证券投资基金从业考试 笔记(时间相关)

热门文章

  1. hdu5823 (附带数的二进制子集)
  2. 解析css之position
  3. virtualbox怎么共享文件夹 linux,Virtualbox中Ubuntu设置共享文件夹
  4. django异常日志_【python小随笔】Django+错误日志(配置Django报错文件指定位置)...
  5. java获取页面标签_java获取网页源代码后,提取标签内容……
  6. js点击取消按钮关闭当前弹框_UI设计中“取消按钮”的分析详解
  7. 浏览器打印设置横向打印_爱普生打印机无线连接设置
  8. 星战前夜服务器维护时间,EVE星战前夜开测时间在什么时候 什么时候测试
  9. mssql php 5.4,PHP5.4如何连接MSSql Server2005
  10. 将jar添加到发布目录_第32批免购置税新能源车型目录发布;通用BEV3平台将入华...