解析
首先考虑如何构造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(!isdigit(c)) {if(c=='-')f=-1;c=getchar();}while(isdigit(c)) {x=x*10+(c^48);c=getchar();}return x*f;
}
int n,m,op;int main(){//freopen("a.in","r",stdin);//freopen("a.out","w",stdout);n=read();m=read();int l=1,r=n;for(int i=1;i<=m;i++){if(op&1) printf("%d ",r--);else printf("%d ",l++);op^=1;}while(l<=r){if(op&1) printf("%d ",l++);else printf("%d ",r--);}return 0;
}
/**/