0
点赞
收藏
分享

微信扫一扫

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

题干:

Permutation p is an ordered set of integers p1,   p2,   ...,   pn, consisting of ndistinct positive integers not larger than n. We'll denote as n 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.

Examples

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.

题目大意:

数列 p 是 1~n 的一个全排列。现在你的任务是找到一个数列 p ,长度为 n,并且满足 |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn|这些数中只有 k 个不同的值。 (1 ≤ k < n ≤ 1e5).

解题报告:

  发现肯定有解,因为若极限情况k=n-1,则1,n,2,n-1,3,n-2,这样可以保证相邻两个数的差值都是不同的值,所以想到构造方法就是这样,构造完K+1个数,剩下的都让他相邻即可(即差值为1)。注意如果k是偶数那最终从大到小,如果k是偶数那最终要由小到大构造。

AC代码;

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define FF first
#define SS second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int n,k;
int main()
{
cin>>n>>k;
int l=1,r=n;
for(int i = 1; i<=k; i++) {
if(i&1) printf("%d ",l++);
else printf("%d ",r--);
}
if(k&1) for(int i = l; i<=r; i++) printf("%d ",i);
else for(int i = r; i>=l; i--) printf("%d ",i);
return 0 ;
}

 


举报

相关推荐

0 条评论