HDU 1536 - S-Nim(SG)

战舰V3移植CANopenNode并驱动电机全流程 第三部分是电机的对象字典(也就是节点的OD)中的索引,长度2个字节。索引发送的是小段模式,比如这一部分为0X40 0X60,实际操作的索引地址为0X6040。第一部分是COB-ID,长度1个字节,电机的node-ID默认为0x01,所以报文ID一直是601。第五部分是要写入的数据,数据发送的时候是小端模式,低字节数据先发送,长度由第二部分决定。配置定时器6,时间为1ms,根据公式计算得到参数PSC取72-1,ARR取1000-1。第二部分是CMD,长度1个字节,其实就是数据部分的长度, 阅读详情

S-Nim

Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4585    Accepted Submission(s): 1989


Problem Description
Arthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as follows:


  The starting position has a number of heaps, all containing some, not necessarily equal, number of beads.

  The players take turns chosing a heap and removing a positive number of beads from it.

  The first player not able to make a move, loses.


Arthur and Caroll really enjoyed playing this simple game until they recently learned an easy way to always be able to find the best move:


  Xor the number of beads in the heaps in the current position (i.e. if we have 2, 4 and 7 the xor-sum will be 1 as 2 xor 4 xor 7 = 1).

  If the xor-sum is 0, too bad, you will lose.

  Otherwise, move such that the xor-sum becomes 0. This is always possible.


It is quite easy to convince oneself that this works. Consider these facts:

  The player that takes the last bead wins.

  After the winning player's last move the xor-sum will be 0.

  The xor-sum will change after every move.


Which means that if you make sure that the xor-sum always is 0 when you have made your move, your opponent will never be able to win, and, thus, you will win.

Understandibly it is no fun to play a game when both players know how to play perfectly (ignorance is bliss). Fourtunately, Arthur and Caroll soon came up with a similar game, S-Nim, that seemed to solve this problem. Each player is now only allowed to remove a number of beads in some predefined set S, e.g. if we have S =(2, 5) each player is only allowed to remove 2 or 5 beads. Now it is not always possible to make the xor-sum 0 and, thus, the strategy above is useless. Or is it?

your job is to write a program that determines if a position of S-Nim is a losing or a winning position. A position is a winning position if there is at least one move to a losing position. A position is a losing position if there are no moves to a losing position. This means, as expected, that a position with no legal moves is a losing position.
 

Input
Input consists of a number of test cases. For each test case: The first line contains a number k (0 < k ≤ 100 describing the size of S, followed by k numbers si (0 < si ≤ 10000) describing S. The second line contains a number m (0 < m ≤ 100) describing the number of positions to evaluate. The next m lines each contain a number l (0 < l ≤ 100) describing the number of heaps and l numbers hi (0 ≤ hi ≤ 10000) describing the number of beads in the heaps. The last test case is followed by a 0 on a line of its own.
 

Output
For each position: If the described position is a winning position print a 'W'.If the described position is a losing position print an 'L'. Print a newline after each test case.
 

Sample Input
2 2 5 3 2 5 12 3 2 4 7 4 2 3 7 12 5 1 2 3 4 5 3 2 5 12 3 2 4 7 4 2 3 7 12 0
 

Sample Output
LWW WWL

======================

题意:每次只能取固定数量的nim。若取子之后所有堆石子数异或值为0,则获胜。

多组输入。

第一行 输入可取石子的个数 以及 可取的数量;

第二行 询问次数。接下来的每行询问 输入堆数以及每堆的石子数,对于每次询问 胜W负L。


#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
int sg[11111];
int s[111],h[111];
int k,m,l;

int dfs(int x){
    if(sg[x]!=-1) return sg[x];
    bool vis[11111];//局部变量,每次递归都有不同的vis数组
    memset(vis,0,sizeof(vis));
    for(int i=0;i<k;i++){
        if(x>=s[i]){
            int tmp=x-s[i];
            vis[dfs(tmp)]=1;
        }
    }
    for(int i=0;;i++){
        if(!vis[i]) return sg[x]=i;
    }
}

int main()
{
    while(~scanf("%d",&k)){
        if(k==0) break;
        for(int i=0;i<k;i++){
            scanf("%d",&s[i]);
        }
        memset(sg,-1,sizeof(sg));
        sg[0]=0;
        scanf("%d",&m);
        while(m--){
            int ans=0;
            scanf("%d",&l);
            for(int i=0;i<l;i++){
                scanf("%d",&h[i]);
                ans^=dfs(h[i]);
            }
            if(ans==0) printf("L");
            else printf("W");
        }
        printf("\n");
    }
    return 0;
}


Dify 本地部署教程 到这里,Dify 就安装完成了,更多操作设置可以参考官方文档,Dify 和 FastGPT 基本上差不多,也可以同时安装一下 FastGPT 进行体验~Docker Compose 部署 | Dify。 阅读详情

相关推荐

手把手教你配置UFS的PSA状态机:WRITE/UNMAP命令实战与LBA映射避雷

本文详细解析了UFS PSA状态机的配置流程,重点探讨了在Pre-soldering状态下WRITE命令的原子性操作原则与单次写入LBA的重要性。通过实战代码示例,指导开发者如何正确初始化PSA环境、切换状态机,并深入剖析了使用UNMAP命令清理LBA映射时的常见陷阱与避雷指南,确保量产数据安全与良率。

weixin_29213525的博客 420

s-nim(一道很麻烦的题)

首先会输入一个n 代表有n种抽牌方式,紧接着n个数字输入; 然后是m表示有m组数据需要判断在这n种抽牌方式下第一个抽牌的人是输或是赢 最后输出m个L/W(这里不太会处理,直接用数组存了) 最后输入0表示输入结束 需要注意的就是需要将n种抽牌方式进行从小到大的排序,不然sg函数中的break要改为continue, 还有就是sg函数的写法需要熟练 #include<iostream> #include<cstring> #include<algorithm> u

pruuu____d的博客 389

机械拆装-基于Unity-总体设计

建立一个机械装配的场景

唐小墨同学的博客 2776

S-Nim + sg函数+博弈+模板

S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 2898    Accepted Submission(s): 1288 Problem Description Arthur and his sister Ca

wenlovingliu的专栏 759

利用ADS设计射频功率放大器

利用ADS设计射频功率放大器 任务: 用飞思卡尔公司的功率放大器芯片ATF27s006NT1设计射频功放,芯片频率范围可达450MHz-3.6GHz。 功放指标: (1) 工作频率:500MHz (2) 增益:G>20dB (3) 电源:+28V (4) 最大输出功率:2W(33dBm) 设计思路 (1)安装DesignKit模型; (2)直流DC扫描; (3)稳定性分析; (4)偏置电路设计及整...

UVM频率 3万+

【β-Boltzmann探索策略】

𝜀是一个介于0和1之间的参数,用于控制探索和利用的比例。当𝜀较大时,智能体更倾向于探索;当𝜀较小时,智能体更倾向于利用已知信息。

m0_59385870的博客 1085

【算法】博弈论

算法

gyk038的博客 171

Python 爬虫进阶:淘宝热卖商品价格走势抓取、反爬与分析全流程

在大数据时代,数据是商业决策的重要依据。电商平台上的商品价格走势,对于商家调整经营策略、消费者选择购买时机都有着关键的参考价值。本篇文章将深入解析如何利用 Python 爬虫抓取淘宝热卖商品的价格走势数据,并应对其中的反爬机制,最后对数据进行分析,带领大家领略 Python 爬虫在电商领域的强大应用。

yansideyucsdn的博客 1058

博弈论入门(Game Theory)

博弈论(Game Theory)一、巴什博弈(Bash Game)操作:代码:例题:1.Brave Game2. kiki's game二、威佐夫博弈(Wythoff Game)操作:代码:例题:1.取石子游戏三、尼姆博弈论(Nim Game)操作:代码:例题:1. Being a Good Boy in Spring Festival四、斐波那契博弈论操作:代码:例题:1. 取石子游戏五、SG函数操作:代码:例题:1. Good Luck in CET-4 Everybody!2. S-Nim 一、巴什博

Hayleyzhou的博客 2723

【感知模块算法】障碍物detect+trace+prediction方向介绍

系列文章目录 提示:这里可以添加系列文章的所有文章的目录,目录需要自己手动添加 TODO:写完再整理 文章目录系列文章目录前言一、多维度看感知问题,体会复杂性二、障碍物/环境目标detect方向1.视觉目标检测方向(1)图像处理认知(2)视觉基础理论部分1、获取数据集---python网页爬虫、买数据、自己录数据、使用开源比赛的数据集2、opencv库的学习3、深度学习框架学习(3)视觉目标检测理论(1)目标检测的概念(2)目标检测的应用场景(3)现有目标检测框架原理及论文【这仅仅是我当初入门学习的框架~

qq_35635374的博客 2894

SAP_SD模块_SAP 消息号VF501(科目确定期间出错)

摘要: SAP SD模块中执行VF02销售开票时出现“科目确定期间出错”(VF501)问题,主要原因是系统无法找到匹配的总账科目。解决方案包括:检查物料主数据和客户主数据中的科目分配组是否维护,核对发票中的对应字段,并通过VKOA事务代码分析科目确定逻辑。若定价过程中配置的科目代码(如Z01)未在VKOA中完整映射(如缺少H1+S5+Z01组合),则会导致内部价格无法关联总账科目。需在SPRO路径下完善科目代码分配配置,确保定价类型与科目代码匹配。本文提供了详细的排查步骤和配置方法,帮助解决开票过账错误。

我小时候很黑的博客 354

博弈论SG函数-算法介绍及例题

一、 基本概念: 1. Impartial Combinatorial Games(ICG) 公平组合游戏: 1. 两名选手 2. 交替进行某种游戏规定的操作,每操作一次,选手可以在有限的操作(操作必须合法)集合中任选一种。 3. 对于游戏的任何一种可能的局面,合法操作集合只取决于这个局面本身,不取决于其它因素(跟选手,以前的所有操作无关) 4. 如果...

Gaoithe的博客 2403

YOLOv11改进有效系列目录 - 包含卷积、主干、检测头、注意力机制、Neck上百种创新机制 - 针对多尺度、小目标、遮挡、恶劣天气等问题

在一些特定情况下,目标检测任务由于多种因素的影响,变得更加复杂和困难。以下是几类常见的困难目标检测场景:1. 小目标检测定义:小目标检测是指当目标在图像中的占比非常小时,模型需要准确识别和定位这些目标。典型场景包括远程监控、卫星图像分析等。挑战1. 低分辨率:由于目标在图像中占据像素较少,细节缺失,特征提取难度增加。2. 特征不足:小目标缺乏明显的形状和纹理特征,容易被复杂背景淹没。3. 检测难度大:由于小目标与背景之间的对比度较低,误检的几率上升。4. 数据不平衡。

qq_64693987的博客 4万+

HDU 1536 S-Nim 博弈,SG函数

HDU 1536 S-Nim博弈,SG函数 传送门:HDU 题意取石子游戏。 先给你一个数组长度k,然后是长度为k的数组。表示合法的取石子个数Si。 然后是n,表示n个询问。 每个询问有一个m,m堆石子,每堆mi个。每次操作允许在某一堆石子中取出Si个石子。问你当前状态谁最后赢。思路算是SG函数入门题吧。 两篇对我理解有帮助的博客:1。2。代码#include <cstdio> #inc

P.H.S 367

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

HDU1536&&HDU1944 S-Nim SG函数

题目链接:HDU1536 S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7162    Accepted Submission(s): 3026 Problem Description Ar

teddywang 396

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

[ACM] hdu 1536 S-Nim(Nim组合博弈 SG函数打表)

S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4004    Accepted Submission(s): 1732 Problem Description Arthur and his siste

逆风的方向 更适合飞翔 2646

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

hdu 1536 S-Nim (SG函数经典题)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1536 题目大意:有一个集合S,里面有k个数,玩取石子游戏,每次只能取S中的一个数,玩n次,分别判断先手胜负。 思路:SG问题经典题,知道SG问题的人应该都会吧。。 不说什么了,不懂得可以看看我转的两篇博客。。 昨天一直听别人说SG什么的,不知道是什么,今天去学了一下,挺厉害的~~ 自己第一道SG题,

沉溺的专栏 1599

HDU1536 S-Nim(sg函数变换规则)

S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9829 Accepted Submission(s): 4038 Problem Description Arthur a...

dmen22330的博客 178

HDU 1536 S-Nim 博弈论-SG定理

Arthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as follows:   The starting position has a number of heaps, all containing some, not necessarily

I'm Growing 379

[hdu 1536 S-Nim] SG 函数

[hdu 1536 S-Nim] SG 函数 题目链接:[hdu 1536 S-Nim] 题意描述:给定KK个数表示 #include #include #include #include #include #include #include #include using namespace std; //#pragma comment(linker, "/STACK

Fighting! 649

hdu 1536、hdu 1944 S-Nim(博弈SG函数)

题意:多组测试数据 ,输入 k个集合S的元素,m种情况,m种(L堆,每堆hi个)。             若存在移动某堆能到达一个必败点,则该点为必胜点,输出W             必败点指无论怎么移动都只能到达必胜点,输出L。 思路:SG函数             每堆看做一个子游戏,SG函数通过递归得到每种堆数的g(); SG函数 定义: 对于一个递增有界的图G(X, F

4452

HDU 1536 S-Nim (SG函数)

S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6364    Accepted Submission(s): 2712 Problem Description Arthur and his sister

随心丶而遇的博客 1710

HDU 1536 S-Nim 博弈求sg函数

一道很基本的博弈求sg函数的题目 唉。。都是泪。。。。。 Description Arthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as follows:    The starting position ha

u013087645的专栏 639

HDU1536:S-Nim(sg函数)

S-Nim Time Limit: 5000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10368Accepted Submission(s): 4262 题目链接:http://acm.hdu.edu.cn/showproblem.php?pi...

dft539533的博客 163

HDU 1536 && HDU 1944 S-Nim (Nim博弈、SG函数模板)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1536 题意: 输入: 2 2 5 3 2 5 12 3 2 4 7 4 2 3 7 12 5 1 2 3 4 5 3 2 5 12 3 2 4 7 4 2 3 7 12 0 输出: LWW WWL 第一行给出可行操作集合大小为k,然后k个数表示一次能在

Benjamin_Z的博客 524

【hdu】1536S-Nim(SG函数)

Problem Description Arthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as follows: The starting position has a number of heaps, all containing some, not necessarily equal, number of beads. The players tak...

_C9的博客 195
上一篇: ZOJ 3529 - A Game Between Alice and Bob(素因子+博弈)
下一篇: HDU 1524 - A Chess Game(SG)
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值