CF183C:Diverse Permutation(构造)
生活随笔
收集整理的這篇文章主要介紹了
CF183C:Diverse Permutation(构造)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
解析
首先考慮如何構(gòu)造k=n-1的情況
發(fā)現(xiàn)令排列為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; } /**/總結(jié)
以上是生活随笔為你收集整理的CF183C:Diverse Permutation(构造)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 上海智能交通创新发展成果亮相进博会,友道
- 下一篇: CF600F:Edge coloring