CF909F AND-permutations 构造

正解:构造

解题报告:

QAQ会了!

放下代码QwQ

 

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rp(i,x,y) for(register ll i=x;i<=y;++i)
#define my(i,x,y) for(register ll i=x;i>=y;--i)

const ll N=100000+10;
ll n,cnt,as[N];

inline ll read()
{
    register char ch=getchar();register ll x=0;register bool y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=getchar();
    if(ch=='-')ch=getchar(),y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=getchar();
    return y?x:-x;
}
inline ll lg(ll x)
{
    ll d=0;
    while((1<<d)<=x)++d;
    return d-1;
}
inline void tsk1(ll x)
{
    if(x&1){printf("NO\n");return;}
    printf("YES\n");
    ll cs=(ll)lg(x),nw=n,gg;cnt=0;
    while(nw)
    {gg=1<<cs;my(i,nw,gg)as[++cnt]=(gg<<1)-1-i;rp(i,gg,nw)as[++cnt]=i;nw=(gg<<1)-2-nw;-cs;}
    my(i,n,1)printf("%lld ",as[i]);
    printf("\n");
}
inline void tsk2(ll x)
{
    if(x==1 || x==5 || x==(1<<lg(x))){printf("NO\n");return;}
    printf("YES\n");cnt=1;
    if(x==3){/*balabal*/;return;}
    if(x==5){/*balabal*/;return;}
    if(x&1){cnt=7;as[1]=7;as[2]=3;as[3]=2;as[4]=6;as[5]=1;as[6]=4;as[7]=5;}
    while(cnt<=x){as[++cnt]=cnt+1;as[++cnt]=cnt-1;}
    if(!(x&1)){as[1]=x;as[x-2]=n;as[x-1]=1;as[x]=n-2;}
    rp(i,1,n)printf("%lld ",as[i]);
}

int main()
{
    n=read();
    tsk1(n);tsk2(n);
    return 0;
}
View Code

 

 

猜你喜欢

转载自www.cnblogs.com/lqsukida/p/10314411.html