Werewolf——困难版本

PTA Werewolf PTA Werewolf 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 we... 阅读详情

Werewolf(狼人杀) is a game in which theplayers are partitioned into two parties: the werewolves and the human beings.Suppose that in a game,

player #1 said: "Player #2 is awerewolf.";

player #2 said: "Player #3 is ahuman.";

player #3 said: "Player #4 is awerewolf.";

player #4 said: "Player #5 is ahuman."; and

player #5 said: "Player #4 is ahuman.".

Given that there were 2 werewolves amongthem, at least one but not all the werewolves were lying, and there wereexactly 2 liers. Can you point out the werewolves?

Now you are asked to solve a hardervertion of this problem: given that there were N players, with M werewolvesamong them, at least one but not all the werewolves were lying, and there wereexactly L liers. You are supposed to point out the werewolves.

【Input Specification】

Each input file contains one test case.For each case, the first line gives three positive integer N (5 ≤ N ≤ 100), M and L (2 ≤ M,L < N). Then N lines follow and the i-th line gives the statementof the i-th player (1 ≤ i ≤ N),which is represented by the index of the player with a positive sign for ahuman and a negative sign for a werewolf.

【Output Specification】

If a solution exists, print in a line indescending order the indices of the M werewolves. The numbers must be separatedby exactly one space with no extra spaces at the beginning or the end of theline. If there are more than one solution, you must output the largest solutionsequence -- 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 larger than B. Incase there is no solution, simply print No Solution.

【Sample Input 1】

5 2 2

1 -2

2 +3

3 -4

4 +5

5 +4

【Sample Output 1】

4 1

【Sample Input 2】

6 2 3

-2

+3

-4

+5

+4

-3

【Sample Output 2】

6 4

【Sample Input 3】

6 2 5

-2

+3

-4

+5

+4

+6

【Sample Output 3】

No Solution

我的解法

#include<bits/stdc++.h>
using namespace std;
int record[100],iswolf[100];
int N,M,L,lier,lierwolf;
vector <int> wolf;

void DFS(int x)
{
    int i;
    
    if(wolf.size()==M)
    {
        lier=lierwolf=0;
        for(i=1;i<=N;i++)
        {
            if((record[i]>0&&iswolf[abs(record[i])]==1)||(record[i]<0&&iswolf[abs(record[i])]==0))
            {
                lier++;//the heart 
                if(iswolf[i]==1) lierwolf++;
            }
        }
        
        if(lier==L&&lierwolf>0&&lierwolf<M)
        {
            for(i=0;i<M;i++)
            {
                if(i==M-1)
                {
                    printf("%d",wolf[i]);
                }
                else
                {
                    printf("%d ",wolf[i]);
                }
            }
            exit(0);//哦哇利达 
        }
        return;//b t f
    }
    
    for(i=x;i>0;i--)
    {
        if(wolf.size()+i<M) break; 
        wolf.push_back(i);
        iswolf[i]=1;
        DFS(i-1);
        wolf.pop_back();
        iswolf[i]=0;
    }
}

int main()
{
    int i;
    
    scanf("%d %d %d",&N,&M,&L);
    //判断数据是否非法 
    if(N<5||N>100) 
    {
        return 0;
    }
    else if(M<2||M>N||L<2||L>N) 
    {
        return 0;
    }
    //初始化 
    for(i=1;i<=N;i++)
    {
        record[i]=0;
    }
    //主程序 
    for(i=1;i<=N;i++) 
    {
        scanf("%d", &record[i]);
    }
    DFS(N);
    printf("No solutiong");
}

思路DFS剪枝

PAT Top 1022 Werewolf (35) PAT Top 1022 Werewolf (35)题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code 题目描述 Input Specification: Output Specification: Sample Input: Sample Output: 解题思路 从甲级过来的... 阅读详情

相关推荐

Unity手游优化实战:用GPU Instancing把草地渲染的DrawCall从8000降到20(附完整Shader)

本文详细介绍了Unity手游中利用GPU Instancing技术优化草地渲染的实战方法,将DrawCall从8000降至20。通过Shader改造和性能优化技巧,开发者可以在移动端实现高效渲染,显著提升游戏性能。文章包含完整的Shader代码和优化策略,适合Unity开发者学习应用。

weixin_33691817的博客 489

【题解】【PAT甲】1148 Werewolf - Simple Version (20 分)

题目链接 PTA | 程序设计类实验辅助教学平台 题目描述 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 ..

Elephant_King的博客 782

VirtualBox虚拟机上ubuntu系统安装问题记:显示画面太小、启动就异常退出等

报错:Failed to load R0 module D:/VMMR0.r0: The path is not clean of leading double slashes: ‘D:/VMMR0.r0’ (VERR_SUPLIB_PATH_NOT_CLEAN).解决方法特别简单,就是安装VIrtualBox的时候不要安装在CDE等盘根目录下。首先VirtualBox的下载安装过程是比较简单的,此处就不赘述了。然后E盘下新建个目录,安装到这个目录下就可解决。

qq_42595610的博客 2826

PAT 甲级 1148  Werewolf - Simple Version

1148Werewolf - Simple Version(20 point(s)) 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 sai...

漫浸天空的雨色的备忘录~ 810

ST-LINK调试STM32H743必看:CubeMX工程中缺失的这行代码导致程序跑飞

本文深入剖析了使用ST-LINK调试STM32H743时,因CubeMX工程中缺失电源电压档位配置代码而导致程序跑飞或出现“Can not access memory”错误的问题。文章解释了H7系列电源与时钟耦合的核心原理,提供了具体的代码修复方案和系统化的调试排查思路,帮助开发者从根本上解决这一常见调试困境。

weixin_29191669的博客 281

《UDS协议从入门到精通》系列——图解0x27:安全访问

什么是安全访问服务?应用场景和基本原理是什么?全网最直观详细的图解UDS-0x27:安全访问服务!!

车载系统攻城狮 7238

Werewolf(狼人杀)DFS与回溯算法

看来结果还是很准确的()

shjsjdisi的博客 991

SPMI协议学习总结

SPMI(System Power Management Interface)是由MIPI(Mobile Industry Processor Interface)联盟定义的一种硬件接口标准,它主要用于移动设备中,连接SoC(System on Chip)处理器系统的集成电源控制器与一个或多个电源管理IC(PMIC),以实现精确的电源管理

歌颂苦难的行为是无耻的; 1086

「1148」Werewolf - Simple Version

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

weixin_52435933的博客 443

微信小程序云开发 - 实现商家转账到零钱(微信企业付款到零钱) V3功能流程及完整实例代码,过微信云开发的云函数实现企业付款到零钱(提供详细示例源码纯云函数实现,证书、密钥、签名等各种常见问题解决方案

企业付款到零钱(微信小程序提现功能,提现到零钱)微信小程序-云函数实现微信企业付款到零钱功能,实现微信商户号中的企业付款到零钱的功能,微信小程序+云开发+商家转账至零钱+微信小程序用户提现,使用云开发环境的云函数实现微信小程序的支付功能,微信小程序实现微信企业付款到零钱功能的流程,V3 V2基于微信云开发的商家转账至零钱,小程序云函数企业付款到零钱功能实现,云开发实现微信商户支付企业付款到零钱功能,不用服务器纯云函数实现,详细示例代码demo教程,API证书错误,转账不到账怎么办,密钥生成有误,转账失败,有

🏆 前端领域优质创作者 1万+

零基础学习CANoe Panel(17)—— Panel CAPL Function

CANoe内置了几个CAPLFunction,允许我们在CAPL运行时动态的更改Panel控件的属性,比如打开某个panel,禁用某个控件,更改控件颜色等。

蚂蚁小兵 3520

PAT (顶级) 升级版 7-1 Werewolf harder version(15分)

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: ...

weixin_43934110的博客 3341

PyTorch深度学习实战(29)——变分自编码器(Variational Autoencoder, VAE)

变分自编码器 (Variational Autoencoder, VAE) 是一种结合了自编码器和概率建模的生成模型,通过编码器将输入数据映射到潜在空间中的概率分布,并通过解码器将从潜在空间采样得到的潜在变量映射回原始数据空间,实现了数据的生成和特征学习。

盼小辉丶的博客 1万+

ubuntu 15.10 代号“Wily Werewolf”

Mark Shuttleworth在google plus上公布了下个版本Ubuntu 15.10开发代号“Wily Werewolf”,意思是狡诈的狼人。 这是一个里程碑,Ubuntu第一个版本就是以字母“W”开头,现在又回到”W”,不免让人感慨。当时Mark Shuttleworth离开Debian,开启了Ubuntu的路程,Ubuntu也成为了最受欢迎的Linux发行版本 Ubu

Moriarty_221的专栏 836

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Werewolf 项目使用教程

Werewolf 项目使用教程 1. 项目目录结构及介绍 werewolf/ ├── app/ │ ├── controllers/ │ ├── models/ │ ├── views/ │ └── routes.js ├── config/ │ ├── database.js │ ├── environment.js │ └── settings.js ├── pub...

gitblog_01074的博客 805

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

pat顶级1022 Werewolf (35 point(s))

欢迎访问我的pat顶级题解目录哦 https://blog.youkuaiyun.com/richenyunqi/article/details/86751676 题目描述 算法设计 这道题是pat甲级1148 Werewolf - Simple Version、pat乙级1089 狼人杀-简单版的升级版,依然采取暴力枚举的方法。将每个人所说的话保存在一维数组a的a[1]-a[n]中。利用深度优先搜索从n向...

日沉云起的博客 2731

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

[IOI2018]werewolf狼人

好像很久没更博客了呢~ [IOI2018]werewolf狼人 题目链接 洛谷 题解 可以将题意转化为 求从\(S\)出发只经过大于\(L\)的点构成的集合\(∩\)从\(E\)只经过小于\(R\)的点是否为空。 我们建\(2\)颗\(kruskal\)重构树\(A,B\)。 \(A\)为每条边的两个点中取较小的点为权值所构成的最大生成树对应的重构树。 \(B\)为每条边的两个点中取较大...

dichanpan2699的博客 296

如何在自己的服务器部署Werewolf for Telegram:6步从零搭建完整指南

Werewolf for Telegram 是一款在 Telegram 中运行完整狼人杀对局的开源机器人,支持多语言、多种游戏模式(经典、Amnesia、Chaos)以及 GIF 动画。本文将带你通过 6 个步骤,在自己的 Windows 服务器上从零部署 Werewolf for Telegram,搭建一个专属的 Telegram 狼人杀机器人。 [![Werewolf for Telegra

gitblog_00622的博客 704

Werewolf for Telegram 运维指南:/replacenodes 零停机滚动更新与多节点监控实战

Werewolf for Telegram 是一款运行在 Telegram 平台上的狼人杀机器人,本指南面向新手运维,详解 `/replacenodes` 零停机滚动更新方法与多节点监控实战,帮助你安全升级 Node 进程、保障玩家游戏体验不中断。 [![Werewolf for Telegram 狼人杀机器人多节点部署架构](https://raw.gitcode.com/gh_mirrors

gitblog_00239的博客 484

[IOI2018] werewolf 狼人

[IOI2018] werewolf 狼人 IOI2018题解 (其实原题强制在线,要用主席树) 代码: 注意: 1.下标从0~n-1 2.kruskal重构树开始有n个节点,tot从n开始,++tot #include<bits/stdc++.h> #define reg register int #define il inline #define numb ...

weixin_34393428的博客 154

PAT顶级1022 Werewolf(甲级1148升级版)

PAT顶级1022 Werewolf(甲级1148升级版) 题目: 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...

weixin_44742521的博客 1835

PAT甲级刷题之路——A1148 Werewolf - Simple Version

PAT A1148 Werewolf - Simple Version原题如下题意自己的想法错误总结错误1错误2AC代码结语 原题如下 题意 每个玩家说出一个人是狼或者人,其中有两个人说谎,且其中一个为狼。 自己的想法 三层循环就可以解决。其中一二层表示狼的标号,第三层表示每个人的指向。 错误总结 错误1 每个人说的不一定是自己,也可以说说谎的人指向的不一定是自己可能是别人,但被指向的人不一...

qq_43677396的博客 541

探索神秘的狼人杀服务器:werewolf_server

探索神秘的狼人杀服务器:werewolf_server 去发现同类优质开源项目:https://gitcode.com/ 在当今社交娱乐领域中,线上游戏已经成为人们休闲互动的重要方式之一。如果你是狼人杀游戏的爱好者,那么这款开源项目—— 将会是一个令人兴奋的发现。本文将带你深入了解它的技术内核、功能用途及独特之处。 项目简介 werewolf_server 是一个基于 Node.js 的在线狼人杀...

gitblog_00081的博客 630

HDU 6370 Werewolf

题目:HDU 6370 Werewolf 题意: 一群人玩狼杀,但是只有两种身份,村和狼,然后分别指认别人的身份 村一定说真话,而狼可以说真话说假话,最后问有几个人一定是村,有几个人一定是铁狼 思路: 先是铁村的个数,假设所有人都是狼,显然这个情况是合法的,所以铁村的个数是0,重点就是铁狼的个数 把评价当成边,先忽略狼边,建立一条有向的村边,用村边建图就会有很多个联通块...

weixin_38287798的博客 296

1022 Werewolf (35 分)

要求:和甲级1148 Werewolf - Simple Version (20 分)一样,不过多了两个参数,狼人数和说谎的人。相比之下就跟复杂一点。 方法:和甲级的方法相差不大,都是穷举。看别人称之为暴力+剪枝??剪枝算法我也不懂, 参考一篇博客浅谈搜索剪枝:剪枝一种生动的比喻:把不会产生答案的,或不必要的枝条“剪掉”。 代码参考博客:PAT 1022. Werewolf (35)。他还加...

lianwaiyuwusheng的博客 1928
上一篇: 银行家算法——操作系统的运用
下一篇: 拼字检索——
Whtiewww
博客等级 码龄7年 54粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值