CF 483C Diverse Permutation(构造)

直流电机双闭环调速系统MATLAB仿真 Chopper-Fed DC Motor Drive This example shows a Chopper-Fed DC Motor Drive. Description The DC motor is fed by the DC source through a chopper which consists of GTO thyristor and free-wheeling diode ... 阅读详情
C. Diverse Permutation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of n distinct positive integers not larger than n. We'll denote as nthe length of permutation p1,   p2,   ...,   pn.

Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.

Input

The single line of the input contains two space-separated positive integers n, k (1 ≤ k < n ≤ 105).

Output

Print n integers forming the permutation. If there are multiple answers, print any of them.

Examples
input
Copy
3 2
output
Copy
1 3 2
input
Copy
3 1
output
Copy
1 2 3
input
Copy
5 2
output
Copy
1 3 2 4 5
Note

By |x| we denote the absolute value of number x.

题意:

从1-n的数中构造出一个序列,使得相邻数的差的绝对值的不同值的个数恰好为k,构造出这样的序列。

思路:

可以发现这样的一件事,当我们有n个数,k=n-1的时候,例如n=5,k=4

我们可以把1放第一个,第二个为1+4=5,第三个是5-3=2,第四个是2+2=4,第五个是4-1=3。这样刚好用了n个数不重复。

所以我们可以想到,前面的我们用递增的序列,保证前面差值均为1,后面再从差值为n-1开始往后按照上面的发现来构造,就一定能构造出这样的序列来。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int a[maxn];
int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k))
    {
        int remain=k;
        int i;
        int f=1;
        for(i=1;i<=n-k;i++)
        {
            a[i]=i;
        }
        for(;i<=n;i++)
        {
            if(f)
            {
                f=0;
                a[i]=a[i-1]+remain;
                remain--;
            }
            else
            {
                f=1;
                a[i]=a[i-1]-remain;
                remain--;
            }
        }
        for(int i=1;i<=n;i++)
        {
            if(i==n)
                printf("%d\n",a[i]);
            else
                printf("%d ",a[i]);
        }
    }
    return 0;
}

广东省道路工程检测练习试题(单选题)真题 1.一般项目的合格点率应达到( ),且不合格点的最大偏差值不得大于规定允许偏差值的1.5倍。A.不低于75%B.不低于80%C.不低于85%D.不低于90%答案:B2.进行土路基平整度检测时,当路宽小于9m,检测点数应为( )A.1B.2C.3D.4答案:A3.根据《城镇道路工程施工与质量验收规范》,在分部工程中,根据工种、材料、施工工艺等划分的是( )A.单位工程B.分项工程C.分部工程D.工序工程答案:B4.根据《城镇道路工程施工与质量验收规范》,土方路基压实度的检测频率为每1000m每压实层抽检( ) 阅读详情

相关推荐

谷歌DreamFusion使用方法及实例详解

DreamFusion 是谷歌提出的基于文本生成3D模型的突破性技术,无需3D训练数据,通过2D扩散模型(如Imagen)与NeRF(神经辐射场)结合实现。以下为使用社区开源实现(如。)的详细步骤及实例。

主攻大数据 人工智能 物联网 安全 低空经济等方向。mtsc 、gtest特邀分享嘉宾 1043

CF183C:Diverse Permutation(构造)

解析 首先考虑如何构造k=n-1的情况 发现令排列为1,n,2,n-1…即可 那么在k不等于n-1时 只需要让前k项与上面的序列相同,后面公差为1即可 代码 #include<bits/stdc++.h> using namespace std; #define ll long long #define ull unsigned long long const int N=2e5+100; ll read() { ll x=0,f=1;char c=getchar(); while(!isd

BUG_Creater_jie的博客 320

海豚调度器(dolphinscheduler)再次使用,添加钉钉预警

1,首先我们部署是海豚调度器 1.3.8版本,由于页面只有邮件预警,所以在了解源码的同时,需要添加钉钉预警 2,说明,这一块是同事搞的,不是我搞的,新版本的dolphinscheduler已经有了钉钉模块,只是新版本还没有发布 3,我们现在只是添加简单的钉钉预警,任务成功或者失败会发送邮件+钉钉 4,具体操作 找到最新的源码devhttps://github1s.com/apache/dolphinscheduler/blob/dev/dolphinscheduler-alert/src/ma...

qq_31866793的博客 3084

蓝桥杯C++——Diverse Permutation

一、题目 二、思路 三、代码 #include<bits/stdc++.h> using namespace std; int main() { int a[100001]; int n,k,i; scanf("%d %d",&n,&k); a[1]=1; for(i=2;k>=1;i++) { if(i%2==0) a[i]=a[i-1]+k; else a[i].

weixin_54098256的博客 420

XPe开发初体验(一)XPe概述

XP Embedded是微软Windows Embedded产品线中非常重要的一环,不过比起大名鼎鼎的Windows Embedded CE,XPe显得过于低调了。在接下来的一段时间里,我希望能够用六篇的篇幅来描述一下XPe的整个开发过程。这个系列文章主要是针对有Windows编程经验,但是没有嵌入式开发经验的开发者,提供一些概念和开发过程的初步介绍。XP Embedded是一个基于Windo

aawolf = new Mobile.MVP 1万+

e-puck场景搭建

可以注意到一个黑色的小窗口出现在三维视图的左上角。它显示了电子吸盘机器人的摄像头拍摄的图像。该图像将保持黑色,直到机器人的控制器明确启用相机。最后,单击右上角的“x”可以关闭它。在对话框中,选择PROTO节点(Webots项目)/robots/gctronic/e-puck/e-puck(Robot)。一个电子吸盘机器人应该出现在竞技场的中央。通过按Alt+左键单击+拖动,对机器人施加力。无法对WoodenBox节点施加力,因为默认情况下,它们没有质量,并且被视为粘在地板上。将新控制器与机器人链接。

weixin_66540163的博客 767

Permutation(思维题)

DescriptionA permutationp is an ordered group of numbers p1,   p2,   ...,   pn, consisting of n distinct positive integers, each is no more than n. We'll define number n as the length of permutation p...

Baiyi_destroyer的博客 556

【HOJ系列】HOJ判题机部署

【HOJ系列】HOJ判题机部署

随风浪仔的专栏 904

Diverse Permutation(构造)

C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Permutation p is an ordered set of integers ...

Simone chou... 273

UNet 改进(3):CBAM模块的融合创新

CBAM模块可以灵活地添加到网络的不同位置,本实现选择在初始卷积后添加,既提升了性能又不过度增加计算负担。UNet_CBAM通过集成注意力机制,使网络能够自动聚焦于图像中最相关的区域和特征通道,从而提升了分割性能。然而,传统的UNet在处理复杂场景时,对所有空间位置和通道特征一视同仁,这可能导致对重要特征的关注不足。在实际应用中,特别是在医学图像分析等需要精确分割的场景中,UNet_CBAM展现出了优异的性能。:CBAM添加的计算量很小,却能带来显著的性能提升,具有很好的性价比。

2401_82355416的博客 1644

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

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

qq_35635374的博客 2894

Diverse Permutation

题意

思维迷宫 703

YOLOv11改进 | Conv篇 | 2024最新轻量化自适应提取模块LAE助力边缘设备部署计算(附代码 + 修改教程 + 运行教程)

本文给大家带来的一个改进机制是最新由LSM-YOLO提出的轻量化自适应特征提取(Lightweight Adaptive Extraction, LAE)模块,其是LSM-YOLO模型中的关键模块,旨在进行多尺度特征提取,同时降低计算成本。LAE通过以下方式实现更有效的特征提取:多尺度特征提取、自适应特征提取。LAE模块可以在不增加额外参数的情况下提高了模型对ROI区域的检测性能。​欢迎大家订阅我的专栏一起学习YOLO!YOLOv11改进系列专栏——本专栏持续复习各种顶会内容——科研必备目录一、本文介绍。

Snu77的博客 4057

CF483C Diverse Permutation

CF483C Diverse Permutation 题目传送门 题意翻译: 构造一个长度为n的排列,使得集合 {∣pi−pi+1∣}\{|p_i-p_{i+1}|\}{∣pi​−pi+1​∣} 的大小为 kkk 。n<=105n<=10^5n<=105 思路: 构造题 简化问题,我们考虑怎么用 k+1k+1k+1 个数构造出答案,这样剩下的数从小到大放就可以了 显然我们可以这样构造: ai=ai−1+(k−i+1)(i%2=1)a_{i}=a_{i-1}+(k-i+1)(i\%2=1)a

Melancholy的博客 437

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

lwip-2.0.3

lwip是瑞典计算机科学院(SICS)的Adam Dunkels 开发的一个小型开源的TCP/IP协议栈。实现的重点是在保持TCP协议主要功能的基础上减少对RAM 的占用。

CodeForces-483C Diverse Permutation(构造)

C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Permutation p is an ordered set of in

十分残念的博客 413

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

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

CF#275 (Div. 2) C(数学构造)

C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Permutation p is an ordered set of in

代码艺术的道与术 1345

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

CF 482A(Diverse Permutation-相邻距离不同数为k的1~n全排列构造)

A. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Permutation p is an ordered set of in

nike0good |Oier&ACMer | 熟能生巧 2739

A. Diverse Permutation

解题说明:此题是要确保一列

无知的我 1272

【CodeForces - 483C】Diverse Permutation(思维构造)

题干: Permutationpis an ordered set of integersp1,   p2,   ...,   pn, consisting ofndistinct positive integers not larger thann. We'll denote asnthe length of permutationp1,   p2,   ...,   pn. ...

xuanweiace的博客 413

codeforces 483C.Diverse Permutation

题目意思:给出 n 和 k,要求输出一个含有 n 个数的排列 p1, p2, ...,pn,使得 |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| 恰好有 k 个不同的数。注意,p1, p2, ..., pn 每个数是不相等的,而且不大于 n。

小张的专栏 1060

codeforces 482A Diverse Permutation 贪心

传送门:cf 482A A. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Permutation p is an

飞火扑蛾的专栏 1333

SD省队集训2019Day5之“CF483C”

cf483C(题号疑似有误) 题目描述 构造一个长度为n的排列,使得集合\(\{|p_i-p_{i+1}|\}\)的大小为k。n<=10^5 做法 构造题。 考虑让\(|p_i-p_{i+1}|=k-i+1\),这样,k+1项后就可以构造出这个集合。然后把剩下的从小到大排序放过去即可。 如何让\(|p_i-p_{i+1}|=k-i+1\)呢?可以这样:1, k+1, 2, k, 3, k-1...

weixin_30439131的博客 227

codeforces Round #275(div2) C解题报告

C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Permutation p is an ordered set of in

旅行者西瓜 940

C. Building Permutation

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Permutation p is an ordered set of integers p1,  p2,  ...,  pn

无知的我 1878

CodeForces 483C Diverse Permutation

Diverse PermutationTime Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u DescriptionPermutationp is an ordered set of integers p1,   p2,   …,   pn, consisting of n distinct pos

swust_fang 891

Codeforces Round #275 (Div. 2) --C Diverse Permutation

题目链接:Diverse Permutation Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pe

sxk 1294
上一篇: CF 483B Friends and Presents(二分)
下一篇: CF 483D Interesting Array(线段树)
Timeclimber
博客等级 码龄9年 25粉丝 198原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值