hdu6130_Kolakoski_模拟递推

CCF认证 行车路线 CCF认证行车路线行车路线原题连接 描述: 小明和小芳出去乡村玩,小明负责开车,小芳来导航。小芳将可能的道路分为大道和小道。大道比较好走,每走1公里小明会增加1的疲劳度。小道不好走,如果连续走小道,小明的疲劳值会快速增加,连续走s公里小明会增加s2的疲劳度。例如:有5个路口,1号路口到2号路口为小道,2号路口到3号路口为小道,3号路口到4号路口为大道,4号路口到5号路口为小道,相邻路口 阅读详情

hdu6130_Kolakoski_模拟递推

描述

This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This sequence consists of 1 and 2, and its first term equals 1. Besides, if you see adjacent and equal terms as one group, you will get 1,22,11,2,1,22,1,22,11,2,11,22,1……. Count number of terms in every group, you will get the sequence itself. Now, the sequence can be uniquely determined. Please tell HazelFan its nth element.

输入

The first line contains a positive integer T(1≤T≤5), denoting the number of test cases.
For each test case:
A single line contains a positive integer n(1≤n≤107).

输出

For each test case:
A single line contains a nonnegative integer, denoting the answer.

样例输入

2
1
2

样例输出

1
2

题意

  • 开始读了半天,意思就是有这么一个序列1,2,2,1……,然后可以转化为1,22,11…..这么个序列,同时,第二个序列的每一项 bi 的数字若为2位数,那么对应的 ai 等于2,若 bi 是一位数,那么对应的 ai 就是1。
  • 现在需要求出给出 an 的值。

思路

  • 首先我们已经知道了一部分的a序列和b序列,现在我们开始打表,把a序列求出来即可。
  • 我们用两个下标indexa,indexb来表示分别表示要求得 a[i] 的下标以及 b[i] 的下标(b[i]实际不用求出)。那么我们在求 a[indexa] 时,先假定一定不与 a[indexa-1] 相同,然后我们看a[indexb],如果值是2,那么说明b[indexb]应该是两位数,那么a[indexa]和a[indexa+1]一定是相同的。如果b[indexb]是1,那么说明a[indexa]与a[indexa+1]一定不同。
  • 对于假设a[indexa]一定不能与a[indexa-1],因为我们做到了如果a[indexa]==a[indexa+1]就更新两个值。所以假设是成立的。

AC代码

    #include<iostream>
    #include<cstdio>
    using namespace std;

    const int maxn = 1e7 +5;

    int a[maxn] = {1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1};
    int n;

    int main()
    {
        int indexa = 20;
        int indexb = 13;

        while(indexa < 1e7)
        {
            int temp = a[indexa - 1];
            if(temp == 1)
            {
                a[indexa] = 2;
            }
            else if(temp == 2)
            {
                a[indexa] = 1;
            }

            if(a[indexb] == 1)
            {
                indexa ++ ;
                indexb ++;
            }

            else if(a[indexb] == 2)
            {
                if(temp == 1)
                {
                    a[indexa + 1] = 2;  
                }       

                else 
                    a[indexa + 1] = 1;

                indexa +=2;
                indexb +=1;
            }
        }

        int T;
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d",&n);
            cout<<a[n-1]<<endl;
        }

        return 0;
    }
POJ4115:鸣人和佐助(广搜) POJ4115:鸣人和佐助 描述 已知一张地图(以二维矩阵的形式表示)以及佐助和鸣人的位置。地图上的每个位置都可以走到,只不过有些位置上有大蛇丸的手下,需要先打败大蛇丸的手下才能到这些位置。鸣人有一定数量的查克拉,每一个单位的查克拉可以打败一个大蛇丸的手下。假设鸣人可以往上下左右四个方向移动,每移动一个距离需要花费1个单位时间,打败大蛇丸的手下不需要时间。如果鸣人查克拉消耗完了,则只可以走 阅读详情

相关推荐

天津大学OJ_2017_07_12比赛I题L-The math problem

L-The math problem Description: Given an array a with n intergers, please tell me the max(aj−ai),0≤i≤j≤n−1. Input: The input consists of multiple test cases. The first line contains an

WaveBridge的博客 2190

Kolakosiki序列C++

这是Kolakosiki序列:1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1 …… 该序列由1和2组成,其第一项等于1。此外,如果将相邻的相同数字视为一组,则将获得1,22,11,2,1,22,1,22,11,2,11,22,1…… 计算每组数字的数量,您将获得序列本身。 所以,序列可以唯一确定。 求其第n(1≤n≤1e7)个元素的值。#include <vector

lzypdc的博客 454

深搜最短路径+剪枝——POJ1724:ROADS

POJ1724:ROADS 深度优先搜索找最短路径,剪枝

WaveBridge的博客 1770

17暑假多校联赛7.11 HDU 6130 Kolakoski

KolakoskiTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)  Problem DescriptionThis is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This sequence c

小学生 1837

springboot+shardingsphere+druid 实现基于时间的水平分表

使用shardingsphere基于时间字段的动态水平分片。

weixin_42207940的博客 2634

复现HumanMAC(HumanMAC: Masked Motion Completion for Human Motion Prediction)

Human3.6M和HumanEva-I都放到data目录下(记得将data_multi_modal-20250320T022408Z-001.zip和humaneva_multi_modal-20250320T022412Z-001.zip解压缩并且分别重命名为data_multi_modal和humaneva_multi_modal)。生成的gif存放在inference目录下zero_shot_<INDEX>下的out目录下。新建一个data目录,将

qq_52643100的博客 841

Kolakoski HDU多校签到题 6130

Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This sequence consists of 1 and 2, and its first term equals 1. Besides, if you see adjacent and eq

turtle的博客 280

分组背包问题(MCKP)三大算法对比:贪心、Dyer-Zemel和动态规划谁更强?

本文深入对比了分组背包问题(MCKP)的三大主流算法:贪心算法、Dyer-Zemel算法和动态规划。通过分析各自的原理、实现及性能表现,揭示了贪心算法速度快但非最优,动态规划精确但受限于规模,而Dyer-Zemel算法则在效率与最优性间取得了最佳平衡,是解决中等至大规模MCKP问题的首选方案。

vscode6remote的博客 234

杭电 Kolakoski

Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This sequence consists of 1 and 2, and its first term equals 1. Besides, if you see adjacent and

ESESZB的博客 2747

Gephi实战指南——从数据导入到可视化输出

本文详细介绍了Gephi数据可视化工具的使用方法,从数据导入到可视化输出的全流程实战指南。涵盖Gephi三大工作区功能、数据导入技巧、图形编辑进阶操作以及专业级可视化输出方案,帮助用户高效完成社交网络分析等复杂任务。

weixin_28731223的博客 491

ArcGIS+PLUS+InVEST三件套:从零搞定生态系统服务模拟预测(附完整数据包)

本文详细介绍了如何整合ArcGIS、PLUS模型和InVEST模型,构建一套完整的生态系统服务模拟预测工作流。内容涵盖从统一数据预处理、PLUS模型多情景模拟,到InVEST模型量化评估的全过程,并提供了关键脚本和避坑指南,旨在帮助研究者和从业者高效解决土地利用变化与生态系统服务评估结合的实际难题。

weixin_42522857的博客 145

Kolakoski

Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This sequence consists of 1 and 2, and its first term equals 1. Besides, if you see adjacent and

Joe19310的博客 2595

华为OD机试2025A卷 - 分苹果(Java & Python& JS & C++ & C )

华为OD机试2025A卷 - 分苹果(Java & Python& JS & C++ & C )

算法大师! 726

HDU 6130 Kolakoski

Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This sequence consists of 1 and 2, and its first term equals 1. Besides, if you see adjacent and equal term

贾作真时真亦贾的博客 735

“华为杯”研究生数学建模竞赛2019年-【华为杯】D题:汽车行驶工况构建(附获奖论文和MATLAB代码实现)

映了汽车道路行驶的运动学特征。准差、加速度标准差这九个特征参数用于后续的数据分析,建立了合理的汽车运动特征评。特征参数与所属类特征参数的特征值的相关性大小替代误差进行排序的,计算得到汽车行。对于问题一,我们首先对原始数据进行了时间变量转换,将原本的年月日时分秒的计。紧接着进行了运动学片段的划分,引入九个特征参数,通过主成分分析、本文研究的是汽车行驶工况构建,汽车行驶工况是描述汽车行驶的速度。的合理性评价标准,对两种方法都进行了合理性评价,得到的。进行了合理性评价,得到了最优的汽车行驶工况曲线。

getusushu的博客 1006

卫星姿态控制的隐形力量:为何必须计算每一个旋转部件的角动量

在静谧的太空中,一颗对地观测卫星正将高清相机精准地对准地面目标。与此同时,它内部的动量轮在飞速旋转,太阳能帆板在缓慢转向以追踪太阳,甚至某个科学载荷的制冷机也在高频运转。你是否曾想过,卫星是如何在这些内部“小宇宙”的运动中,保持自身姿态极致的稳定与精确的

ScilogyHunter的博客 981

HDU 6130-Kolakoski(Kolakoski序列)

address :http://acm.hdu.edu.cn/showproblem.php?pid=6130Problem Description This is Kolakosiki sequence: 1,2,2,1,1,2,1,2,2,1,2,2,1,1,2,1,1,2,2,1……. This sequence consists of 1 and 2, and its first term

知足常乐的博客 2177

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

POJ1190:生日蛋糕(深搜+剪枝)

POJ1190:生日蛋糕 描述: 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体。 设从下往上数第i(1 <= i <= M)层蛋糕是半径为Ri, 高度为Hi的圆柱。当i < M时,要求Ri > Ri+1且Hi > Hi+1。 由于要在蛋糕上抹奶油,为尽可能节约经费,我们希望蛋糕外表面(最下一层的下底面除外)的面积Q最小。

WaveBridge的博客 1672

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

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

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

贪心例题集

贪心POJ3617贪心POJ3617描述 给定长度为N的字符串s,要构造一个长度为N的字符串T。期初,T是一个空串。 然后以下操作:从S的头部删除一个字符,加到T的尾部。 从S的尾部删除一个字符,加到T的尾部。 目标是要使构造的字典序尽可能小。 思路 我们很容易想到每次就看字符串S的头尾,把小的删除掉放到T的尾部就好。但是存在一个问题,当头尾的字符一样的时候,就必须要比较下一个字符的大小

WaveBridge的博客 1068

深度学习工具包 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")

优先队列简单介绍+例题POJ2431

优先队列一、优先队列简单介绍 优先队列是一种数据结构,能够实现插入一个数值,并且取出最小值(最大值)并删除等操作。 能够使用某种二叉树来实现优先队列,这种二叉树叫“堆”。堆分为小根堆和大根堆,小根堆的意思就是所有的子节点值一定不比父亲的值小,大根堆就是所有的子节点值一定不比父亲的节点值大。并且向堆中插入和取最小的值(或最大)的值得复杂度都为O(logn)。 二、STL中的优先队列都要加头文件 #in

WaveBridge的博客 1052

Vijos P1034 回文数

Vijos P1034 回文数 描述 若一个数(首位不为零)从左向右读与从右向左读都一样,我们就将其称之为回文数。 例如:给定一个10进制数56,将56加65(即把56从右向左读),得到121是一个回文数。 又如:对于10进制数87: STEP1:87+78 = 165 STEP2:165+561 = 726 STEP3:726+627 = 1353 S

WaveBridge的博客 901

POJ2084—Game of Connections(c++高精度)

Game of Connections description: This is a small but ancient game. You are supposed to write down the numbers 1, 2, 3, … , 2n - 1, 2n consecutively in clockwise order on the ground to form a ci

WaveBridge的博客 730

广度优先搜索入门

广度优先搜索入门实现流程(用 queue ): 放入初始结点 S0 到 Open 表中(待访问)。 如果 Open 表为空,失败退出。 不为空,取出队头放入 Close 表(标记已经访问过),即为节点 n。 考察n是否为目标节点。是则成功退出。 若不是,看 n 是否可扩展,不可扩展则退回第 2 步。 若可扩展,则将其不再 Close 表和 Open (真正实现判重一般是为每个节点设置一个标记,而不是

WaveBridge的博客 672

POJ3692——Kindergarten(最大二分匹配)

POJ3692——Kindergarten description: In a kindergarten, there are a lot of kids. All girls of the kids know each other and all boys also know each other. In addition to that, some girls and boys k

WaveBridge的博客 671

添加好友(快速幂取模)

“盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛D题——添加好友 描述 Tony最近喜欢上了龙之谷游戏,所以他想叫上他的好友组建一个公会来一起享受这款游戏。 Tony一共有n个好友,他可以叫上任意k(1<=k<=n)个好友来组建公会,并且所有好友都会答应他的请求。问Tony一共可以有多少种方案组建这个公会? 只要不是完全相同的人组建的方案视为不同方案

WaveBridge的博客 650
上一篇: 福州大学2271x——弗洛伊德最短路
下一篇: 线段树基础与模板与简单应用
WaveBridge
博客等级 码龄10年 8粉丝 26原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值