PAT A1148 Werewolf - Simple Version (20 分)——暴力遍历,负负得正
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≤N≤100). Then N lines follow and the i-th line gives the statement of the i-th player (1≤i≤N), 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 A=a[1],...,a[M] and B=b[1],...,b[M], if there exists 0≤k<M such that a[i]=b[i] (i≤k) and a[k+1]<b[k+1], 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
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <set>
#include <vector>
using namespace std;
const int maxn=;
int wolf[maxn];
int state[maxn];
struct node{
int w[];
};
bool cmp(node n1,node n2){
return n1.w[]==n2.w[]?n1.w[]<n2.w[]:n1.w[]<n2.w[];
}
vector<node> v;
int main(){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++){
int tmp;
scanf("%d",&tmp);
state[i]=tmp;
}
int i,j,flag=;
for(i=;i<n;i++){
for(j=i+;j<=n;j++){
fill(wolf,wolf+maxn,);
wolf[i]=-;
wolf[j]=-;
int cnt=;
for(int k=;k<=n;k++){
if(wolf[abs(state[k])]*state[k]<){
cnt++;
}
}
if(cnt!=) continue;
else{
if(wolf[abs(state[i])]*state[i]*wolf[abs(state[j])]*state[j]<){
printf("%d %d",i,j);
return ;
}
}
}
}
printf("No Solution");
}
注意点:一开始想设置两个人说谎,然后再去判断是不是总共两个狼人一个说谎一个没有,一直有问题,分析了一下是逻辑很有问题,因为会存在有的人在陈述时会被多次点到,有的人一次都没点到,这样根据说不说谎去判断会出现很多问题,而且最后输出狼人而不是说谎的人,也会很麻烦。
因此这题需要设置两个狼人,然后判断是不是两个人说谎,并且是一狼一人。看了大佬的思路才发现判断是不是说谎只要看这个人的陈述和这个人说的人的真实身份乘起来是不是小于0,小于0就是说谎,负负得正,正负得负的思路。
PAT A1148 Werewolf - Simple Version (20 分)——暴力遍历,负负得正的更多相关文章
- PAT 1148 Werewolf - Simple Version
1148 Werewolf - Simple Version (20 分) Werewolf(狼人杀) is a game in which the players are partitioned ...
- PAT 1148 Werewolf - Simple Version [难理解]
1148 Werewolf - Simple Version (20 分) Werewolf(狼人杀) is a game in which the players are partitioned i ...
- PAT_A1148#Werewolf - Simple Version
Source: PAT 1148 Werewolf - Simple Version (20 分) Description: Werewolf(狼人杀) is a game in which the ...
- PAT(A) 1148 Werewolf - Simple Version(Java)逻辑推理
题目链接:1148 Werewolf - Simple Version (20 point(s)) Description Werewolf(狼人杀) is a game in which the p ...
- PAT乙级:1088 三人行 (20分)
PAT乙级:1088 三人行 (20分) 题干 子曰:"三人行,必有我师焉.择其善者而从之,其不善者而改之." 本题给定甲.乙.丙三个人的能力值关系为:甲的能力值确定是 2 位正整 ...
- PAT乙级:1064 朋友数 (20分)
PAT乙级:1064 朋友数 (20分) 题干 如果两个整数各位数字的和是一样的,则被称为是"朋友数",而那个公共的和就是它们的"朋友证号".例如 123 和 ...
- PAT 甲级 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- pat 1108 Finding Average(20 分)
1108 Finding Average(20 分) The basic task is simple: given N real numbers, you are supposed to calcu ...
- pat 1046 Shortest Distance(20 分) (线段树)
1046 Shortest Distance(20 分) The task is really simple: given N exits on a highway which forms a sim ...
随机推荐
- List排序Collections.sort 重写compare
static List<Integer> intList = Arrays.asList(2,5,7, 3, 1); public static void main(String[] ar ...
- MAC MYSQ忘记密码重置方法
网友的方法,记个笔记请勿转载. step1: 关闭mysql服务: 苹果->系统偏好设置->最下边点mysql 在弹出页面中 关闭mysql服务(点击stop mysql server) ...
- 透明度 rgba 和 opacity 的区别
rgba: 使用方式:rgba(255, 255, 255, .5) 最后一个参数表示透明度取值范围 0 ~1 只作用于元素的颜色或其背景色. opacity : 使用方式:opacity : ...
- 使用普通用户执行 docker
CentOS 版本 7.4,Docker 版本 docker-1.13 及以下 ll /var/run/docker.sock srw-rw----. 1 root root 0 May 25 14: ...
- GitHub使用SSHkey进行连接
SSH key的配置基本是我们使用git必备的配置,配置好可以避免频繁的在git push或者git pull的时候输入账号和密码 本来我的SSH key早就配置好了,结果他不起作用了,那就在配置一次 ...
- vue和webpack打包 项目相对路径修改
一般vue使用webpack打包是整个工程的根目录,但是很多情况下都是把vue打包后的文件在某子目录下. 修改: 1,打开index.js assetsPublicPath:'/' 改为: asset ...
- Salesforce中的单点登录简介
单点登录的定义 引自维基百科: 单点登录(英语:Single sign-on,缩写为 SSO),又译为单一签入,一种对于许多相互关连,但是又是各自独立的软件系统,提供访问控制的属性.当拥有这项属性时, ...
- Salesforce DX 简介
Salesforce DX Salesforce DX (Salesforce Developer Experience) 是 Salesforce 推出的一个新的开发和部署模式,旨在提供更好的开发者 ...
- 安卓界面之Toolbar+tablayout+viewpager仿WhatsApp界面样式
实现界面: 布局代码: <?xml version="1.0" encoding="utf-8"?> <android.support.con ...
- 【Java入门提高篇】Day27 Java容器类详解(九)LinkedList详解
这次介绍一下List接口的另一个践行者——LinkedList,这是一位集诸多技能于一身的List接口践行者,可谓十八般武艺,样样精通,栈.队列.双端队列.链表.双向链表都可以用它来模拟,话不多说,赶 ...