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). Then Nlines follow and the i-th line gives the statement of the i-th player (1), 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 [ and [, if there exists 0 such that [ (i≤k) and [, 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

Solution:

  mmp,看了半天题目,以为要用一个复杂算法来推导,半天想不出来,后来才发现,20分的题,你千万不要看高了他,该暴力就暴力,该遍历就遍历,不要想用什么高大上的算法!!!

  这道题就是使用暴力遍历,从1开始,每两个个人假设为狼人,然后去验证几个人说谎了,并且是不是一个好人和一个狼人说谎了,对,就这么简单,就他妈的用遍历!!!

  

 #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int>speak(n + ), name(n + , );
for (int i = ; i <= n; ++i)cin >> speak[i];
for (int i = ; i <= n; ++i)//假设i,j是狼人
{
for (int j = i + ; j <= n; ++j)
{
vector<int>lie, v(n + , );//都是好人
v[i] = v[j] = -;//标记狼人
for (int t = ; t <= n; ++t)
if (v[abs(speak[t])] * speak[t] < )//说是好人,但实际是狼人,他说谎了
lie.push_back(t);
if (lie.size() == && v[lie[]] + v[lie[]] == )//一个好人撒谎,一个坏人撒谎
{
cout << i << " " << j << endl;
return ;
}
}
}
cout << "No Solution" << endl;
return ;
}

PAT甲级——A1148 WerewolfSimpleVersion【20】的更多相关文章

  1. PAT 甲级 1035 Password (20 分)(简单题)

    1035 Password (20 分)   To prepare for PAT, the judge sometimes has to generate random passwords for ...

  2. PAT甲级——1035 Password (20分)

    To prepare for PAT, the judge sometimes has to generate random passwords for the users. The problem ...

  3. PAT 甲级 1008 Elevator (20)(代码)

    1008 Elevator (20)(20 分) The highest building in our city has only one elevator. A request list is m ...

  4. PAT 甲级 1077 Kuchiguse (20 分)(简单,找最大相同后缀)

    1077 Kuchiguse (20 分)   The Japanese language is notorious for its sentence ending particles. Person ...

  5. PAT 甲级 1061 Dating (20 分)(位置也要相同,题目看不懂)

    1061 Dating (20 分)   Sherlock Holmes received a note with some strange strings: Let's date! 3485djDk ...

  6. PAT 甲级 1008 Elevator (20)(20 分)模拟水题

    题目翻译: 1008.电梯 在我们的城市里,最高的建筑物里只有一部电梯.有一份由N个正数组成的请求列表.这些数表示电梯将会以规定的顺序在哪些楼层停下.电梯升高一层需要6秒,下降一层需要4秒.每次停下电 ...

  7. PAT甲级——1061 Dating (20分)

    Sherlock Holmes received a note with some strange strings: Let's date! 3485djDkxh4hhGE 2984akDfkkkkg ...

  8. PAT甲级——1005.SpellItRight(20分)

    Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output e ...

  9. PAT甲级——1077.Kuchiguse(20分)

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...

随机推荐

  1. java知识点拾遗:)

    一篇有用的java基础知识总结http://www.cnblogs.com/xuwujing/p/8638329.html 枚举:http://blog.csdn.net/qq_27093465/ar ...

  2. C# 获取微信小程序access_token

    /// <summary> /// 获取access_token /// </summary> /// <returns></returns> publ ...

  3. (转)微信调用扫码和支付功能是都报错 the permission value is offline verifying

    原文地址:https://blog.csdn.net/qq_34794885/article/details/98504970

  4. [Fw]初探linux中断系统(2)

    初探linux中断系统(2) 中断系统初始化的过程 用来初始化中断系统的函数位于arch/x86/kernel/irqinit.c,定义如下 void __init init_IRQ(void){ i ...

  5. oracle中Varchar2和nvarchar2的区别

    在oracle 11g下测试了下varchar2与nvarchar2这两种类型,网上有很多关于这两种类型的区别的帖子,我还是自己测试了下. varchar2(size type),size最大为400 ...

  6. shell位置参数的遍历

  7. SurfaceView的基本使用(转)

    转自:https://www.cnblogs.com/zhangyingai/p/7087371.html SurfaceView的基本使用   一.引入: Android提供了View来进行绘图处理 ...

  8. 力扣 ——Linked List Cycle II(环形链表 II) python实现

    题目描述: 中文: 给定一个链表,返回链表开始入环的第一个节点. 如果链表无环,则返回 null. 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始). ...

  9. java23种设计模式(二)-- 建造者模式和原型模式

    一.建造者模式 将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创造不同的表示. 特点: (1).在某些属性没有赋值之前,复杂对象不能作为一个完整的产品使用.比如汽车包括方向盘.车门.发动机 ...

  10. jQuery HTML-删除元素

    html <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...