PAT_A1148#Werewolf - Simple Version
Source:
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 ;
}
最新文章
- 设置maven默认的JDK版本
- poj2184 01背包变形,价值为可为负数
- ASCII值对照表
- C#操作Excel数据增删改查(转)
- Android studio gradle 打包 那些事
- Android中moveTo、lineTo、quadTo、cubicTo、arcTo详解(实例)
- HDU 2147 kiki&#39;s game
- IOS把图片缓存到本地的几种方法
- Python——Mysql
- LeetCode(125):验证回文串
- 3.3 MathType自动公式编号和对齐
- Hadoop shell命令
- ogg - 从oracle到mysql的同步
- Androidpn 简单实现及分析
- MySQL大事务导致的Insert慢的案例分析
- windows rails new demo时候出错Make sure that `gem install mysql2 -v &#39;0.3.15&#39;` succeeds before bundling.
- php读取大文件如日志文件
- 怎么用JavaScript实现tab切换
- 【Python3的进制扫盲】
- Js组件layer的使用