Source:

PAT 1148 Werewolf - Simple Version (20 分)

Description:

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 N lines 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

Keys:

  • 简单模拟

Attention:

  • 基本思路就是穷举,一种方法是找liar,另一种是找wolf,第一种比较直观,第二种更快一些;

Code:

 /*
Data: 2019-08-04 16:06:11
Problem: PAT_A1148#Werewolf - Simple Version
AC: 16:40 题目大意:
狼人杀,N名玩家互爆对方身份;
一共有两只狼,一共两人撒谎,
狼中有一人撒谎,民中有一人撒谎
找出两只狼; 基本思路:
id[i]表示身份;
liar[i]表示i号玩家是否说谎,cnt统计说谎人数;
假设i,j是狼人,遍历各个玩家发言
liar[i]+liar[j]==1且cnt==2时,符合要求,退出循环
*/
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int M=1e3; int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif // ONLINE_JUDGE int n,spk[M];
scanf("%d", &n);
for(int i=; i<=n; i++)
scanf("%d", &spk[i]);
for(int i=; i<n; i++)
{
for(int j=i+; j<=n; j++)
{
int liar[M]={},id[M],cnt=;
fill(id+,id+n+,);
id[i]=id[j]=-;
for(int k=; k<=n; k++)
{
if(spk[k]*id[abs(spk[k])]<)
{
liar[k]=;
cnt++;
}
}
if(liar[i]+liar[j]== && cnt==)
{
printf("%d %d", i,j);
n=;
}
}
}
if(n)
printf("No Solution"); return ;
}

PAT_A1148#Werewolf - Simple Version的更多相关文章

  1. PAT 1148 Werewolf - Simple Version

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

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

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

  3. PAT(A) 1148 Werewolf - Simple Version(Java)逻辑推理

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

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

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

  5. 1148 Werewolf - Simple Version (20 分)

    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. [Functional Programming] Write a simple version of Maybe

    Maybe has two types: Just / Nothing. Just() will just return the value that passed in. Nothing retur ...

  8. 2018.9.8pat秋季甲级考试

    第一次参加pat考试,结果很惨,只做了中间两道题,还有一个测试点错误,所以最终只得了不到50分.题目是甲级练习题的1148-1151. 考试时有些紧张,第一题第二题开始测试样例都运行不正确,但是调试程 ...

  9. PAT (Advanced Level) Practice(更新中)

    Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...

随机推荐

  1. HPC2013小节

    对于高性能计算,三个分支能耗.高性能.容错.下面我对会议的主要内容作一个小节,很多问题也是不求甚解. 下面针对大会内容,我主要总结如下,会有了解不周的地方,欢迎讨论:大会主要报告分成3个方向,1.基础 ...

  2. Android自己定义Toast

    一.引言 在开发的过程中你会发现Android自身的Toast提示有很多限制,比方我想自己定义Toast的动画.自己定义一个美观的View显示在Toast中.很多其它的是让Toast显示指定的时长等等 ...

  3. [LeetCode][Java] Minimum Depth of Binary Tree

    题目: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the ...

  4. HDU 2110-Crisis of HDU(母函数)

    Crisis of HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) To ...

  5. linux驱动由浅入深系列:tinyalsa(tinymix/tinycap/tinyplay/tinypcminfo)音频子系统之一【转】

    本文转载自:http://blog.csdn.net/radianceblau/article/details/64125411 目前linux中主流的音频体系结构是ALSA(Advanced Lin ...

  6. 格伦布编码——rice编码无非是golomb编码M为2^x的特例

    格伦布编码 格伦布编码是一种无失真资料压缩方法,由数学家所罗门·格伦布在1960年代提出. Rice编码 Robert F. Rice提出Rice 编码,是以哥伦布编码为基础做改良而更简易的前置码.R ...

  7. [Contest Hunter#17-C] 舞动的夜晚

    [题目链接] http://contest-hunter.org:83/contest/CH%20Round%20%2317/%E8%88%9E%E5%8A%A8%E7%9A%84%E5%A4%9C% ...

  8. PCB 生产周期计算逻辑与代码实现

    PCB生产周期计算逻辑: 代码实现: 调用代码: getWeek(DateTime.Now.Date, ); 周期计算逻辑: /// <summary> /// 获取周期 /// < ...

  9. B - Cows and Poker Game

    Problem description There are n cows playing poker at a table. For the current betting phase, each p ...

  10. Redis学习笔记(五)- 数据类型之set类型

    Redis 的set是string类型的无序集合.set元素最大可以包含(2的32次方-1)个元素.set的是通过hash table实现的,所以添加,删除,查找的复杂度都是O(1).hash tab ...