Source:

PAT A1148 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:

  • 穷举即可

Code:

 1 /*
 2 Data: 2019-05-28 21:56:56
 3 Problem: PAT_A1148#Werewolf - Simple Version
 4 AC: 25:00
 5
 6 题目大意:
 7 游戏中有两个狼人和若干平民,依次指认狼人或平民,狼和民各一人说谎
 8 根据发言找出两个狼人
 9 输入:
10 第一行,人数5<=N<=100;
11 接下来N行,表示1<=i<=N号玩家的发言,正数指认为民,负数指认为狼
12 输出:
13 从小到大输出两个狼人玩家序号,结果不唯一则输出较小序列
14 */
15 #include<cstdio>
16 #include<algorithm>
17 #include<cmath>
18 using namespace std;
19 const int M=110;
20 int say[M],wolf[M],liar[M];
21
22 int main()
23 {
24 #ifdef ONLINE_JUDGE
25 #else
26     freopen("Test.txt", "r", stdin);
27 #endif // ONLINE_JUDGE
28
29     int n;
30     scanf("%d", &n);
31     for(int i=1; i<=n; i++)
32         scanf("%d", &say[i]);
33     for(int i=1; i<=n; i++)
34     {
35         for(int j=i+1; j<=n; j++)
36         {
37             fill(liar,liar+M,0);
38             fill(wolf,wolf+M,1);
39             wolf[i]=-1;wolf[j]=-1;
40             int cnt=0;
41             for(int k=1; k<=n; k++)
42             {
43                 if(say[k]*wolf[abs(say[k])]<0){
44                     cnt++;liar[k]=1;
45                 }
46                 else
47                     wolf[abs(say[k])]=say[k];
48             }
49             if(cnt==2 && liar[i]+liar[j]==1){
50                 printf("%d %d\n", i,j);
51                 return 0;
52             }
53         }
54     }
55     printf("No Solution\n");
56
57     return 0;
58 }

转载于:https://www.cnblogs.com/blue-lin/p/10940560.html

PAT_A1148#Werewolf - Simple Version相关推荐

  1. PAT(甲级)2018年秋季考试 7-1 Werewolf - Simple Version (20 分)

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

  2. 【PAT甲级题解记录】1148 Werewolf - Simple Version (20 分)

    [PAT甲级题解记录]1148 Werewolf - Simple Version (20 分) 前言 Problem:1148 Werewolf - Simple Version (20 分) Ta ...

  3. PAT甲级 -- 1148 Werewolf - Simple Version (20 分)

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

  4. 1148 Werewolf - Simple Version (20 分)

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

  5. PAT 1148 Werewolf – Simple Version – 甲级

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

  6. 【PAT】A1148 Werewolf - Simple Version

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

  7. 1148 Werewolf - Simple Version

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

  8. 【PTA Advanced】1148 Werewolf - Simple Version(C++)

    目录 题目 Input Specification: Output Specification: Sample Input 1: Sample Output 1: Sample Input 2: Sa ...

  9. 「1148」Werewolf - Simple Version

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

最新文章

  1. CBWFQ技术简介及应用配置事例
  2. 计算机网络(谢希仁第八版)第四章:网络层
  3. python查询天气
  4. 微信小程序获取openid
  5. Linux下程序开机启动
  6. 私人linux远程连接,Linux远程连接 - osc_5g1gl9wp的个人空间 - OSCHINA - 中文开源技术交流社区...
  7. gg修改器修改数值没有用怎么办_风灵月影是谁?风灵月影修改器大全
  8. 智能门锁到底安不安全?
  9. NRF24L01入门总结
  10. linux驱动 平台设备驱动模型
  11. Excel表格限制编辑,什么原因?
  12. 遥感、遥感技术、遥感卫星、卫星遥感、卫星遥感技术
  13. 计算机开机自检时,电脑开机启动时出现DHCP自检怎么办
  14. android 图片画圆,在Android中画圆形图片的几种办法
  15. connect holder is null问题记录
  16. 统计学三大相关性系数:pearson,spearman,kendall
  17. 高纬度矩阵运算--NumPy
  18. yahoo邮箱foxmail收发
  19. IDEA免费教育申请(不需要教育邮箱,只要你是学生!!!)
  20. 通过css设置canvas背景图片

热门文章

  1. 这个比肩ImageNet的数据集遭MIT紧急下架,原因令人愤怒
  2. 年薪40万,我用的是这套Python学习体系
  3. Exchange Log Collector Script
  4. Swift3中的 GCD
  5. python—函数实例一
  6. 敏捷开发思想及Scrum实践
  7. Nginx + Tomcat 动静分离实现负载均衡
  8. 深入理解JavaScript系列(33):设计模式之策略模式(转)
  9. Google Map API V3调用arcgis发布的瓦片地图服务
  10. 手动配置Hibernate的方法