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. 服务器oracle数据库定时备份

    首先要先建立一个.bat的文件  然后执行这个bat文件 测试是否能得到这个收据库的打包文件. bat文件内容: @echo off@color bdel /f /s /q D:\oracle\bac ...

  2. 记录一次kibana启动Unable to fetch data from reporting collector

    版本不匹配导致 应该es与kibana版本一致 本文链接:https://blog.csdn.net/qq_33293753/article/details/87894882

  3. Aspnetcore下面服务器热更新与配置热加载

    原文:Aspnetcore下面服务器热更新与配置热加载 Asp.net的热更新方案Appdomain在aspnetcore中不被支持了 新的方案如下: 配置文件更新选项 reloadOnChange ...

  4. paint进阶(转)

    转自:https://blog.csdn.net/cquwentao/article/details/51374994 概述 paint的基本绘制方法已经在前面的基本图形绘制中讲解了,这里做的是进阶讲 ...

  5. 力扣——Partition List(分隔链表) python实现

    题目描述: 中文: 给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前. 你应当保留两个分区中每个节点的初始相对位置. 示例: 输入: head = ...

  6. ubuntu Oracle SQL Developer 安装

    一. 官网下载oracle 安装包 二.下载完毕后,检查你的Ubuntu是否安装了tar和alien sudo apt-get install tar sudo apt-get install ali ...

  7. RPC服务治理框架(一)RPC技术

    一.RPC是什么 remote procedure call:远程过程调用 过程就是程序,像调用本地方法一样调用远程的过程 RPC采用Client-Server结构,通过request-respons ...

  8. linux 应用层常用API/命令

    一 API 1. bsearch NAME bsearch - binary search of a sorted array SYNOPSIS #include <stdlib.h> v ...

  9. leetcode-165周赛-1276-不浪费原料的汉堡制作方案

    题目描述: 自己的提交: class Solution: def numOfBurgers(self, tomatoSlices: int, cheeseSlices: int) -> List ...

  10. 云数据库POLARDB产品解读之二:如何做到高性价比

    现在做任何事情都要看投入产出比,对应到数据库上其实就是性价比.POLARDB作为一款阿里自研数据库,经常被问的问题是:性能怎么样?能不能支撑我的业务?价格贵不贵?很显然,在早期调研阶段,对稳定性.可靠 ...