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 ...
随机推荐
- 微信公共号:CTO技术总监
业务价值胜过技术策略: 战略目标胜过具体项目的效益: 内置的互操作胜过定制的集成: 共享服务胜过特定目标的实现: 灵活性胜过优化: 不断演进地提炼胜过在最开始追求完美!
- 2018-01-03 烂尾工程: Java实现的汇编语言编译器
在半年前的中文编程的尝试历程小记中简单介绍了这一项目. 由于短期内估计不会继续进行, 而且这个项目好像是至今个人在中文命名实践中的代码量最大的一个项目, 谨在此作一小结. 最新的源码库在program ...
- Ubuntu18.4中Apache在加不同端口的虚拟主机
1.添加监听端口 sudo vim /etc/apache2/ports.conf Listen 80 Listen 6080 <IfModule ssl_module> ...
- python自动化开发-7
socket编程 Socket是应用层与TCP/IP协议族通信的中间软件抽象层,它是一组接口.在设计模式中,Socket其实就是一个门面模式,它把复杂的TCP/IP协议族隐藏在Socket接口后面,对 ...
- WEB服务器----Apache 安装配置
1.官网下载需要的安装包(包括主安装包和依赖包的下载)可以直接使用Linux的wget进行下载: httpd安装包下载地址:http://mirrors.hust.edu.cn/apache//htt ...
- loadrunner 场景设计-添加Unix、Linux Resources计数器
场景设计-添加Unix.Linux Resources计数器 by:授客 QQ:1033553122 A. 目的 监控要测试的Unix.Linux服务器的资源使用情况 Linux CentOS为例 ...
- Jni 线程JNIEnv,JavaVM,JNI_OnLoad(GetEnv返回NULL?FindClass返回NULL?)
此文章是关于NDK线程的第二篇理论知识笔记.主要有两个点,如下: 1.pthread_create(Too many arguements, expected 1) ?2.线程中如何获取JNIEnv? ...
- 《Inside C#》笔记(二) 初识C#
一 程序的编译.构成 a) 编写C#代码一般用VS,但作者在这儿介绍了使用记事本编写C#代码并编译运行的过程,以便对VS有更深入的认识. 用记事本编写C#代码后,修改文本文件的后缀为.cs,然后用cs ...
- Android--很实用的图片工具类
import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; imp ...
- zookeeper.Net
原文转至:http://www.cnblogs.com/shanyou/p/3221990.html 之前整理过一篇文章<zookeeper 分布式锁服务>,本文介绍的 Zookeeper ...