7-1 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

感觉就是枚举暴力题。。不过我第一个点老不过,后来阅读了一边题目。意思是一个狼人撒谎和一个人撒谎,我理解成了一个狼人一人撒谎或者两个狼人撒谎,那个at least应该被我错误理解了。

思路
二重循环,第一层循环记i为狼人,第二层循环记j为狼人,然后在内循环判断一下当前状态是否满足n个人的陈述,可以的话就打印不然最后就输出不存在

#include <iostream>
#include <math.h>
#define maxsize 105
using namespace std;
int n, seq[maxsize];
bool wolves[maxsize] = {false};
bool validate(int wolfa, int wolfb)
{int z, truen = 0, falsen = 0, wolfly = 0;for (z = 1; z <= n; z++){if ((abs(seq[z]) == wolfa || abs(seq[z]) == wolfb) == (seq[z] < 0))truen++;else{falsen++;if (z == wolfa || z == wolfb)wolfly++;}}return falsen == 2 && wolfly == 1;
}
int main()
{std::ios::sync_with_stdio(false);std::cin.tie(0);cin >> n;for (int i = 1; i <= n; i++)cin >> seq[i];for (int i = 1; i <= n; i++)for (int j = i + 1; j <= n; j++)if (validate(i, j)){int tmps = 0;for (int m = 1; m <= n; m++)if ((m == i || m == j) && tmps == 0){cout << m;tmps++;}else if ((m == i || m == j) && tmps != 0)cout << " " << m;return 0;}cout << "No Solution";return 0;
}

PAT(甲级)2018年秋季考试 7-1 Werewolf - Simple Version (20 分)相关推荐

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

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

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

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

  3. 记PAT 甲级 2021年 秋季考试 经验总结、线上考试细节、考场题解

    1.简单回顾 今天下午考完了秋季的考试,最终得了97分,第一题扣了3分,非常遗憾.还有一个多小时的时候就已经97了,回来和第一题的剩余3分周旋到最后,没能发现问题所在,不停考虑各种,我觉得可能是陷在已 ...

  4. 【PAT甲级 大数运算】1065 A+B and C (64bit) (20 分) Python 全部AC

    题目 初学python,第一次用python刷oj,挑了个简单题试试手. 在大数运算方面,python没有数的大小限制,简直开挂. total = int(input()) for i in rang ...

  5. 【PAT甲级 删除字符串中重复字母】1084 Broken Keyboard (20 分) Java 全部AC

    题目 题解 Java import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamRead ...

  6. 【PAT甲级 U形打印】1031 Hello World for U (20 分) Java版 6/6通过

    题目 一开始没看懂"as squared as possible"和那个max不等式到底是什么意思,看了别人的解答才明白: 如果n % 3 == 0,n正好被3整除,直接n1 = ...

  7. 【PAT甲级 素数判断 进制转换】1015 Reversible Primes (20 分) Java版 4/4通过

    题目 思路: 为了提高效率,判断素数采用打表的方式 先计算100000以内的所有素数,然后如果要判断一个数是否为素数的话,直接与表中比对 题目中的意思是: 首先,判断一个数N1是否为素数 如果N1是素 ...

  8. 【PAT】2020年秋季考试划水准备贴

    1.环境 1.时间 PAT一年有三次考试,春季(2-3),秋季(8-9)和冬季(11-12) 本次考试时间: 2020/09/05 13:30:00 2.地点 PAT在非浙江地区(比如上海),往往都只 ...

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

    1. 我设置了一个结构体变量存储每个人的指控信息 struct IF{int type = 0;int no; }; 这里我发现了一件事,如果结构体只有有参数的构造函数,那么直接声明该结构体类型的数组 ...

最新文章

  1. python 画pr曲线
  2. Xshell 命令后台执行
  3. 【USACO】电子游戏 有条件的背包
  4. 深层神经网络难以训练的原因
  5. 学习笔记(46):Python实战编程-protocol
  6. linux内核双向循环队列,读书笔记之linux内核设计与实现(2)进程调度
  7. centos 卸载软件_一篇看懂!详解-Linux系统中安装软件的三种方法
  8. 微信公开课讲师李卿:小游戏开放 100 天
  9. Three.js使用PointerLockControls控制相机实现第一人称视角
  10. 原创:爱是两个人的事
  11. strcpy_s函数
  12. vue在线预览word踩坑日记
  13. 测试工程师日常工作流程
  14. 自然语言处理——中英文分词工具(还可做词性标注与命名实体识别)
  15. 科技热点周刊|GitLab 上市、LinkedIn 中国停止运营、Visual Studio 2022 正式版将发布
  16. 常山浙西计算机学校,常山这所最早的学校你上过吗?历经三个世纪,他依然在最初的地方等你……...
  17. 佛祖保佑永无Bug—— 最好用的注释插件
  18. abap 发票冲销VF11的BAPI:BAPI_BILLINGDOC_CANCEL1
  19. Python 删除列表中指定的元素
  20. Freebsd 8.4 Vmware 安装及软件配置

热门文章

  1. 计算机应用与软件 sci,国内计算机类期刊 SCI收录:
  2. NLP篇【01】tfidf与bm25介绍与对比
  3. 分享四个非常方便的二维码生成链接
  4. 绝地求生自定义服务器出租,绝地求生自定义服务器测试 可自由设置武器刷新道具掉落...
  5. 云+,技术思维升级之道
  6. torchscript相关知识介绍(二)
  7. 微服务到底该怎么样部署呢?
  8. micropython常用模块有那个_Python常用模块,不明觉厉先马后看
  9. VBA+批处理实现WORD转EXCEL数据分析开发日志
  10. 刀塔OMG塔防1.2.7b单机版使用方法