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+);
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+,);
a[i] = a[j] = -;
for(int k = ; k <= n; k++)
if(v[k]*a[abs(v[k])] < ) lie.push_back(k);
if(lie.size() == && a[lie[]] + a[lie[]] == ){
cout << i << " " << j;
return ;
}
}
}
cout << "No Solution";
return ;
}

1148 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(A) 1148 Werewolf - Simple Version(Java)逻辑推理

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

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

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

  4. 1148 Werewolf - Simple Version

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

  5. PAT_A1148#Werewolf - Simple Version

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

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

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

  7. PTA 07-图5 Saving James Bond - Hard Version (30分)

    07-图5 Saving James Bond - Hard Version   (30分) This time let us consider the situation in the movie ...

  8. PAT 甲级 1041 Be Unique (20 分)

    1041 Be Unique (20 分) Being unique is so important to people on Mars that even their lottery is desi ...

  9. PAT 甲级 1011 World Cup Betting (20)(20 分)

    1011 World Cup Betting (20)(20 分)提问 With the 2010 FIFA World Cup running, football fans the world ov ...

随机推荐

  1. Spring 实例化bean的三种方式

    第一种方法:直接配置Bean <bena id="所需要实例化的一个实例名称" class="包名.类名"/> 例如: 配置文件中的bean.XML ...

  2. C/C++代码覆盖率工具gcov、lcov

    gcov是一个可用于C/C++的代码覆盖工具,是gcc的内建工具.下面介绍一下如何利用gcov来收集代码覆盖信息. 想要用gcov收集代码覆盖信息,需要在gcc编译代码的时候加上这2个选项 “-fpr ...

  3. Sublime Text notes

    1. 设置在窗口右下方显示文件的编码,在user preferences里加上以下的配置 2.设置用新标签页打开新文件而不是用新窗口打开,将以下配置改为false(默认为true)

  4. 自定义JTabbedPane 标签风格

    自定义JTabbedPane 标签风格 2012年03月09日 20:33:12 阅读数:2435 demo 下载地址:http://download.csdn.net/detail/jinannan ...

  5. php抓取网页中的内容

    以下就是几种常用的用php抓取网页中的内容的方法.1.file_get_contentsPHP代码代码如下:>>>>>>>>>>>&g ...

  6. FractalNet(分形网络)

    -Argues that key is transitioning effectively from shallow to deep and residual representations are ...

  7. easyui SWFUpload

    业务背景:实现一个用药人的增加功能,用药人信息中包含附件.如题所示,主要讨论easyui上传的实现.jsp页面代码(弹出框),一个简单的增加页面 div id=addMedicationDlg cla ...

  8. C# -- 泛型(3)

    简介: 前两篇文章讲了关于泛型的一些基础,下面笔者通过这篇文章来给刚刚接触泛型的朋友介绍一下 <1>.原理性的东西----” 泛型的协变和逆变 “ <2>.以及常用的接口--- ...

  9. 使用Oracle(SQL Plus)

    error: connection as sys should be as SYSDBA or SYSOPER 用户名 :sys 密码:  自己设定的database:ORCLconnect as : ...

  10. DataType--时间类型

    SQL SERVER 存储时间的方式和存放浮点数的方式类似,存放时按照一定公式算出一个数值,存放到页面,在读取时按照公式求算出时间值,再按照默认或指定的时间格式展示给用户. 如果存放DATETIME数 ...