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. msgfmt: command not found

    sudo apt-get install gettext

  2. java直接跳转页面

    public static String genForwardHtml(String url, Map<String, String> parameters, String charset ...

  3. Android修改状态栏颜色全方位教程

    关键字:状态栏着色 透明状态栏 沉浸式 白底黑字 Github Demo:https://github.com/imflyn/Eyes 参考文章: Android-transulcent-status ...

  4. java实现发送邮件功能

    项目中实现发送邮件功能,先书写一个小Demo,记录如下: POM.XML中导入依赖 <!-- start java 提供的支持邮件发送相关业务的类 --> <dependency&g ...

  5. Lucene的学习及使用实验

    实验一下Lucene是怎么使用的. 参考:http://www.importnew.com/12715.html (例子比较简单) http://www.yiibai.com/lucene/lucen ...

  6. python之pack布局

    #Pack为一布局管理器,可将它视为一个弹性的容器 '''1.一个空的widget'''#不使用pack # -*- coding: cp936 -*- from Tkinter imp ort * ...

  7. LVS负载均衡之NAT模式部署

    1.LVS的NAT模式介绍 参考自官网:http://www.linuxvirtualserver.org/zh/lvs3.html 由于IPv4中IP地址空间的日益紧张和安全方面的原因,很多网络使用 ...

  8. phpunit与xdebug的使用

    基本说明: 1.xdebug是程序猿在调试程序过程中使用的bug调试暴露工具 windows下安装: 1)下载php对应的dll文件,下载地址:https://xdebug.org/download. ...

  9. unity web项目发布服务器Data file is corrupt (not a Unity W

    楼上问题需要在iis 中配置MIME 加一个 .unity3d MIME类型:application/octet-stream http://www.cnblogs.com/123ing/p/3913 ...

  10. python——socket模块与列表映射

    从socket模块学习中的一段奇怪代码说起 前言:在学习python标准库中的Socket模块中,发现了一段奇怪的代码. import socket def get_constants(prefix) ...