欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

CF183C:Diverse Permutation(构造)

发布时间:2023/12/3 60 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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(!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; } /**/

总结

以上是生活随笔为你收集整理的CF183C:Diverse Permutation(构造)的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。