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 integers p1,   p2,   ...,   pn,
consisting of n distinct positive integers not larger than n.
We'll denote asn the 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 nk (1 ≤ k < n ≤ 105).

Output

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

Sample test(s)
input
3 2
output
1 3 2
input
3 1
output
1 2 3
input
5 2
output
1 3 2 4 5
Note

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


1 10 2 9 3 8 |7 6 5 4 3 2

不同的。

。全为1的

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100000+10)
#define MAXK (100000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
int n,k;
int main()
{
// freopen("CF482A.in","r",stdin);
// freopen(".out","w",stdout); cin>>n>>k;k--;
int l=1,r=n,b=1;
while(l<=r)
{ if (b) printf("%d",l++);
else printf("%d",r--);
if (k) b^=1,k--; if (l<=r) putchar(' ');
}
cout<<endl;
return 0;
}

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

  1. [Codeforces 482A] Diverse Permutation

    [题目链接] https://codeforces.com/contest/482/problem/A [算法] 首先构造一个(k + 1)个数的序列 , 满足它们的差为1-k 对于i > k ...

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

    题目链接:Codeforces Round #275 (Div. 2) C - Diverse Permutation 题意:一串排列1~n.求一个序列当中相邻两项差的绝对值的个数(指绝对值不同的个数 ...

  3. Codeforces Round #275 (Div. 1)A. Diverse Permutation 构造

    Codeforces Round #275 (Div. 1)A. Diverse Permutation Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 ht ...

  4. 构造 Codeforces Round #275 (Div. 2) C. Diverse Permutation

    题目传送门 /* 构造:首先先选好k个不同的值,从1到k,按要求把数字放好,其余的随便放.因为是绝对差值,从n开始一下一上, 这样保证不会超出边界并且以防其余的数相邻绝对值差>k */ /*** ...

  5. codeforces C. Diverse Permutation

    C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. CodeForces 483C Diverse Permutation

    Diverse Permutation Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64 ...

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

    http://codeforces.com/contest/483/problem/C C. Diverse Permutation time limit per test 1 second memo ...

  8. C. Diverse Permutation(Codeforces Round #275(div2)

    C. Diverse Permutation time limit per test 1 second memory limit per test 256 megabytes input standa ...

  9. codeforces C. Diverse Permutation(构造)

    题意:1...n 的全排列中 p1, p2, p3....pn中,找到至少有k个 |p1-p2| , |p2-p3|, ...|pn-1 - pn| 互不相同的元素! 思路: 保证相邻的两个数的差值的 ...

随机推荐

  1. 7zip File: How to Uncompress 7z files on Ubuntu, Debian, Fedora

    转:http://www.thegeekstuff.com/2010/04/7z-7zip-7za-file-compression/ Question: How do I uncompress a ...

  2. 让IE浏览器支持HTML5

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  3. IIS 日志

    查看工具: Log Parser + Log Parser Studio http://www.microsoft.com/en-us/download/details.aspx?displaylan ...

  4. elasticsearch term 查询二:Range Query

    Range Query 将文档与具有一定范围内字词的字段进行匹配. Lucene查询的类型取决于字段类型,对于字符串字段,TermRangeQuery,对于数字/日期字段,查询是NumericRang ...

  5. docker实战——在测试中使用Docker

    在之前几章中介绍的都是Docker的基础知识,了解什么是镜像,docker基本的启动流程,以及如何去运作一个容器等等. 接下来的几个章节将介绍如何在实际开发和测试过程中使用docker. 将Docke ...

  6. Nehe OpenGL lesson 8

    lesson8 Blending: http://nehe.gamedev.net/tutorial/lessons_06__10/17010/ (也许须要特殊手段訪问) There was a re ...

  7. mac重置蓝牙模块

    升级系统后蓝牙鼠标无法连接,蓝牙模块也无法关闭,通过重置 PRAM和SMC解决 PRAM 重置 关机,拔掉所有外设,接上电源. 启动时同时按住 Command, Option, p, r , 听到三次 ...

  8. Odoo8.0中允许用户动态调整TreeView栏位宽度

    现有的Odoo8.0中TreeView的栏位宽度是固定的,不可以手动调整,通过安装第三方插件后,可以实现手工动态调整. 下载模块安装即可.http://download.csdn.net/detail ...

  9. iDempiere = OSGi + ADempiere 一款ERP&CRM&SCM系统、助力中小企业发展

    怀揣着为中小企业量身定做一整套开源软件解决方案的梦想开始了一个网站的搭建.http://osssme.org/ iDempiere = OSGi + ADempiere 一款ERP&CRM&a ...

  10. iOS开发-Swift获取手机设备信息(UIDevice)

    使用UiDevice获取设备信息 获取设备名称 let name = UIDevice.currentDevice().name 获取设备系统名称 let systemName = UIDevice. ...