PAT_A1148#Werewolf - Simple Version
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相关推荐
- 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 ...
- 【PAT甲级题解记录】1148 Werewolf - Simple Version (20 分)
[PAT甲级题解记录]1148 Werewolf - Simple Version (20 分) 前言 Problem:1148 Werewolf - Simple Version (20 分) Ta ...
- PAT甲级 -- 1148 Werewolf - Simple Version (20 分)
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...
- 1148 Werewolf - Simple Version (20 分)
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...
- PAT 1148 Werewolf – Simple Version – 甲级
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...
- 【PAT】A1148 Werewolf - Simple Version
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...
- 1148 Werewolf - Simple Version
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...
- 【PTA Advanced】1148 Werewolf - Simple Version(C++)
目录 题目 Input Specification: Output Specification: Sample Input 1: Sample Output 1: Sample Input 2: Sa ...
- 「1148」Werewolf - Simple Version
Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and th ...
最新文章
- CBWFQ技术简介及应用配置事例
- 计算机网络(谢希仁第八版)第四章:网络层
- python查询天气
- 微信小程序获取openid
- Linux下程序开机启动
- 私人linux远程连接,Linux远程连接 - osc_5g1gl9wp的个人空间 - OSCHINA - 中文开源技术交流社区...
- gg修改器修改数值没有用怎么办_风灵月影是谁?风灵月影修改器大全
- 智能门锁到底安不安全?
- NRF24L01入门总结
- linux驱动 平台设备驱动模型
- Excel表格限制编辑,什么原因?
- 遥感、遥感技术、遥感卫星、卫星遥感、卫星遥感技术
- 计算机开机自检时,电脑开机启动时出现DHCP自检怎么办
- android 图片画圆,在Android中画圆形图片的几种办法
- connect holder is null问题记录
- 统计学三大相关性系数:pearson,spearman,kendall
- 高纬度矩阵运算--NumPy
- yahoo邮箱foxmail收发
- IDEA免费教育申请(不需要教育邮箱,只要你是学生!!!)
- 通过css设置canvas背景图片