hdu3980 Paint Chain SG函数

博弈类题目小结(HDU,POJ,ZOJ) 转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 首先当然要献上一些非常好的学习资料: 基础博弈的小结:http://blog.csdn.net/acm_cxlove/article/details/7854530 经典翻硬币游戏小结:http://blog.csdn.net/ac 阅读详情

Problem Description
Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one player must paint a unpainted beads. Whoever is unable to paint in his turn lose the game. Aekdycoin will take the first move.

Now, they thought this game is too simple, and they want to change some rules. In each turn one player must select a certain number of consecutive unpainted beads to paint. The other rules is The same as the original. Who will win under the rules ?You may assume that both of them are so clever.
 

Input
First line contains T, the number of test cases. Following T line contain 2 integer N, M, indicate the chain has N beads, and each turn one player must paint M consecutive beads. (1 <= N, M <= 1000)
 

Output
For each case, print "Case #idx: " first where idx is the case number start from 1, and the name of the winner.
 

Sample Input
2 3 1 4 2
 

Sample Output
Case #1: aekdycoin Case #2: abcdxyzk

  N个珠子,两个人轮流取连续M个,谁不能取了就输了。

  初步了解了一下SG函数,目前只会用,原理到时再研究。

  简单说就是找当前状态下一步的子状态,如果没有子状态当前sg为0,如果操作某一步后分成了多个子状态,则把他们的sg值异或,看成一个整体作为当前的一个子sg。当前sg的取值为他所有子sg里从0开始sg没有取到的那个值。

  对于这个题,就是记忆化搜索,求出当前状态的SG,判断是否为0。

  先操作一步,把环变成链,这样才能递归。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cstdlib>
#include<cmath>
#define INF 0x3f3f3f3f
#define MAXN 1010
#define MAXM 20010
#define MAXNODE 4*MAXN
#define eps 1e-9
using namespace std;
int T,N,M,sg[MAXN];
int SG(int n){
    if(sg[n]!=-1) return sg[n];
    if(n<M) return sg[n]=0;
    int vis[MAXN]={0};
    memset(vis,0,sizeof(vis));
    for(int i=0;i<=n-M-i;i++) vis[SG(i)^SG(n-M-i)]=1;
    for(int i=0;;i++) if(!vis[i]) return sg[n]=i;
}
int main(){
    freopen("in.txt","r",stdin);
    scanf("%d",&T);
    int cas=0;
    while(T--){
        scanf("%d%d",&N,&M);
        printf("Case #%d: ",++cas);
        memset(sg,-1,sizeof(sg));
        if(N<M){
            printf("abcdxyzk\n");
            continue;
        }
        if(SG(N-M)) printf("abcdxyzk\n");
        else printf("aekdycoin\n");
    }
    return 0;
}


大数据运维面试题及答案 1. 架构组成:- 2 个 NameNode(Active 活跃节点、Standby 备用节点),实时同步元数据(通过 JournalNode 集群,默认 3 个节点,存储 edits 日志,Active 写入、Standby 读取以保持元数据一致);- 容错性强:通过 RDD 的 “ lineage(血缘)” 机制,任务失败时可快速重算,无需从头执行。:集群 “大脑”,管理元数据(文件目录、块位置),实时响应客户端请求,数据存于内存,元数据镜像(fsimage)和编辑日志(edits)持久化到磁盘; 阅读详情

相关推荐

避开这些坑!DS18B20温度读取不准、时序混乱的5个常见问题与调试方法

本文深入解析DS18B20温度传感器在应用中常见的5个问题,包括温度读取不准、时序混乱等,并提供详细的调试方法。通过硬件设计优化、精准延时实现和数据解析技巧,帮助开发者有效解决温度值跳变、初始化失败等典型问题,提升OneWire协议下的温度测量精度。

weixin_29185493的博客 469

hdu 3980 Paint Chain(SG函数)

Paint ChainProblem DescriptionAekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each tur

Darkarts 1万+

PLECS中DLL模块的使用

PLECS中DLL模块的使用 之前发布了一篇文章,介绍如何使用PSIM中的DLL模块。而本篇文章的内容与之类似,不过主角换成了PLECS。 PLECS和PSIM类似,也属于电力电子仿真软件,使用方便,仿真速度快,和Matlab也有一定的联系,有兴趣的可以去试试。PLECS可以利用外部动态链接库(DLL)来调用外部的代码参与仿真,方便复杂控制算法的实现,也有利于后期直接将代码移植到硬件控制器上。

OptimisticPoplar的博客 2725

hdu3980 Paint Chain

Paint Chain Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 897 Accepted Submission(s): 316 Problem Description Aekdycoin and abcdxyzk are

习惯与规则决定命运 1001

VisionPro动态坐标系构建:CogFixtureTool与CogFixtureNPointToNPointTool实战解析

本文深入解析了VisionPro中动态坐标系构建的核心技术,重点对比了CogFixtureTool与CogFixtureNPointToNPointTool的原理与应用。通过实战案例,阐述了如何利用坐标跟随(Fixturing)技术解决工业视觉检测中因零件位置偏移导致的测量不准问题,实现从“固定”到“随动”的思维跃迁,从而构建稳定、精准的检测程序。

weixin_29207439的博客 573

EAST算法(Efficient and Accuracy Scene Text))

1.EAST模型简介 本文介绍的文本检测模型EAST,便简化了中间的过程步骤,直接实现端到端文本检测,优雅简洁,检测的准确性和速度都有了进一步的提升。如下图: 其中,(a)、(b)、(c)、(d)是几种常见的文本检测过程,典型的检测过程包括候选框提取、候选框过滤、bouding box回归、候选框合并等阶段,中间过程比较冗长。而(e)即是本文介绍的EAST模型检测过程,从上图可看出,其过程简化为只有FCN阶段(全卷积网络)、NMS阶段(非极大抑制),中间过程大大缩减,而且输出结果支持文本行、单词的多个角度

博客 9582

hdu3980Paint Chain+SG博弈

Problem Description Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one pla

xtulollipop 1116

从零实现深度学习框架——自动求导神器计算图

本文介绍自动求导神器——计算图,从本篇文章开始介绍一个自定义的求导工具。

日积月累,天道酬勤 4201

HDU 3980 Paint Chain(博弈 SG)

HDU 3980 Paint Chain(博弈 SG)

1440

C#串口通信从入门到精通(27)——高速通信下解决数据处理慢的问题(20ms以内)

本文介绍如何在高速通信情况下解决串口接收的数据来不及处理的问题,由高级工程师多年经验总结而成,绝对是串口领域的实战经验!

qq_34059233的博客 6822

ABAP CDS SELECT, parameters 全面解析:把参数化视图玩明白(含可运行示例)

这篇技术博客介绍了ABAP CDS中参数化视图的用法与实践。文章从业务需求出发,解释了参数化视图的必要性,并详细说明了语法规则、参数类型匹配、视图内部参数引用等关键点。重点展示了在JOIN和ASSOCIATION中传递参数的写法,提供了航线分析的完整业务案例和可运行代码示例。文章还总结了视图实体与DDIC视图的差异、会话变量使用技巧等实践要点,特别强调了JOIN中必须显式传参的语法要求。通过真实场景演示,帮助开发者掌握参数化CDS的高效应用。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 371

hdu3980Paint Chain(博弈+SG函数)

hdu3980Paint Chain(博弈+SG函数) 先来说说SG函数的灵魂就是mex函数,这是一个针对于集合的函数,表示最小的不属于这个集合的非负整数。比如mex{1,2,3,4}=0;mex{0,2,3,4}=1; SG函数想要获取的就是mex{“计算出的集合”}; Problem Description Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none

濡苏的博客 540

嵌套学习 (Nested Learning, NL):赋予AI持续学习能力的革命性范式

嵌套学习(Nested Learning, NL)的核心哲学在于彻底颠覆传统深度学习中将模型架构(Architecture)与优化算法(Optimization)视为两个独立组件的“扁平化”视角 。传统方法通常将神经网络的结构设计和其训练过程分离开来,模型架构是预先定义好的静态蓝图,而优化算法(如SGD、Adam)则是一个外部的、统一的规则引擎,负责在训练期间调整模型参数 。这种分离的视角隐藏了模型内部不同组件之间复杂的梯度流和动态更新过程,将整个学习系统视为一个单一层次的优化问题。然而,嵌套学习范式提出,

步子哥的博客 492

HDU3980 Paint Chain SG函数

题目链接:HDU3980 Paint Chain Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1803    Accepted Submission(s): 629 Problem Description

teddywang 524

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

hdu 3980 Paint Chain 组合游戏 SG函数

题目链接 题意 有一个\(n\)个珠子的环,两人轮流给环上的珠子涂色。规定每次涂色必须涂连续的\(m\)颗珠子,无法继续操作的人输。问先手能否赢。 思路 参考 转化 第一个人取完之后就变成了一条链,现只需要考虑这条链上的操作即可。 SG函数计算 考虑在一个链上涂连续的\(m\)颗珠子这个问题的子问题,记当前有\(x\)颗珠子 \(x\lt m\) 显然已经无法涂了,故\(sg(x)=0\...

ahu12345678的博客 124

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

HDU 3980 Paint Chain(sg函数)

Problem DescriptionAekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one play...

←_← 280

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

HDU - 3980 Paint Chain(sg函数)

Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one player must paint a unp...

Cymbals的博客 352

HDU 3980 Paint Chain(SG函数)

Problem Description: Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one p

蘑菇--走在通往梦想的道路上。 723

HDU---3980:Paint Chain【SG函数】

题意: 两个人轮流给有N个玻璃球的环涂色,每次只能给一段长为M的子段且没有涂过色的玻璃球涂色,不能操作者输 分析: SG函数: SG[x] = mex{SG[y] | y为x能到达的后继点},mex{}返回在自然数中第一个未出现的数,mex{0,1,3,4} = 2;SG[x] = 0,则x为必败点,否则x为必胜点 SG定理: 子游戏SG值的异或和等于全局的SG值 NIM...

KobeDuu 217

HDU3980 Paint Chain(SG函数)

传送门 nnn个点围成一个环,每次每个人可以把连续的mmm个点染色 无法操作的人失败, 问胜负情况 很明显第一个人操作过后,环就变成了一条链 所以可以定义sg[x]sg[x]sg[x]为链长xxx的sgsgsg值 那么显然sg[k]=0 (k∈[0,m−1])sg[k]=0\ (k\in[0,m-1])sg[k]=0 (k∈[0,m−1]) 然后枚举先手第一次把链变成长n−mn-mn−m 所以我们求sg[n−m]sg[n-m]sg[n−m]是后手的胜负状态 注意特判n<mn&lt

jziwjxjd的博客 489

HDU 3980 Paint Chain (sg函数)

Paint Chain Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 804    Accepted Submission(s): 292 Problem Description Aekdycoin and abcdxyzk are...

weixin_34233856的博客 91

HDU 3980 Paint Chain(博弈论,SG函数)

#include<bits/stdc++.h> using namespace std; const int maxn = 1005; int sg[maxn]; int grundy(int n, int m) { if(sg[n] != -1) { return sg[n]; } if(n < m) { return sg[n] = 0; } int ...

Nerdant 437

HDU - 3980-Paint Chain(博弈,SG函数)

题目链接:HDU - 3980-Paint Chain Paint Chain Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2223 Accepted Submission(s): 814 Problem Descrip...

howell 372

hdu 3980 Paint Chain (sg函数 )

Problem Description Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is painted. They take turns to paint the chain. In Each turn one pla

退役的铜牌狗 497

HDU - 3980 Paint Chain(SG函数)

https://vjudge.net/problem/HDU-3980 题意 一串长度为n的柱子,每个人只能给连续的珠子涂色,涂过的不能再涂,不能涂的人就输了,问最后谁获胜。 分析 第一个人先涂m个,就把环变成链了,先手就变为后手。现在考虑长度为N-M的链上的游戏,用子状态来推出当前状态,一个问题的结果是其子问题的结果的亦或,然后使用记忆化推出sg,就知道谁赢了。 #include...

weixin_33806914的博客 177

hdu 3980 Paint Chain 博弈+SG函数 每次选连续M个

Problem Description Aekdycoin and abcdxyzk are playing a game. They get a circle chain with some beads. Initially none of the beads is pain

kongming_acm的专栏 905
上一篇: hdu 3972 1 M possible
下一篇: uva11806 - Cheerleaders 容斥原理
小小小小葱
博客等级 码龄14年 22粉丝 266原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值