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. MYSQL 源码

    http://www.cnblogs.com/wingsless/tag/MySQL/

  2. Libs文件夹下的Jar文件为什么不会自己主动放在Android Private Libraries文件夹下

    简而言之:这个问题就是由jar包反复冲突了! 这个问题一開始我出现了一种"自以为是"的答案,在Android Private Libraries文件夹下的是会打包到project可 ...

  3. [WebGL入门]二十三,反射光的光照效果

    注:文章译自http://wgld.org/,原作者杉本雅広(doxas).文章中假设有我的额外说明.我会加上[lufy:],另外,鄙人webgl研究还不够深入.一些专业词语.假设翻译有误.欢迎大家指 ...

  4. 1360 xth 的玫瑰花

    1360 xth 的玫瑰花  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 这天是rabbit 的生日 ...

  5. jQuery总结03

    1 控制网页元素属性和样式的 jQuery 方法有哪些? 2 利用 jQuery 插入网页节点的方法有哪些? 3 jQuery 中绑定事件是什么,如何解除绑定? 4 jQuery 中的动画效果包括哪些 ...

  6. 邪恶的C++

    曾经看到一篇很有趣的文章,今天转载一下.抱歉的是没有找到最原始的版本,算是遗憾吧. ---------- 华丽的分割线 ---------- Linus曾经(2007年9月)在新闻组gmane.com ...

  7. mysql数据库操作(2)

    上一篇文章我们接触了一些常用的 mysql 语句,当我们需要产生复杂的逻辑的时候,我们需要组合mysql语句,这时候的 mysql 语句又臭又长,那么我们就有必要知道 mysql 语句执行的顺序了. ...

  8. Coursera Algorithms week3 归并排序 练习测验: Counting inversions

    题目原文: An inversion in an array a[] is a pair of entries a[i] and a[j] such that i<j but a[i]>a ...

  9. fopen文件目录问题

    程序当前目录下.如果是在 VC 里面运行的, 这个目录是工程的目录. 如果是双击 exe 运行的, 这个目录就是 exe 所在的目录.

  10. PCB MS SQL SERVER版本管控工具source_safe_for_sql_server

    PCB由于业务关系复杂,业务触发一个事件时,可能需与数据库多个表进行关连处理才能拿到数据结果, 而表关连并不是简单的关连,实际是要进行大量数据筛选,逻辑判断,转换等过程...这个过程是复杂的 想一想, ...