AGC050A AtCoder Jumper

· · 题解

由于每个点最多有两个链接,考虑建立完全二叉树。

发现 2^{10}\ge n,得该方案可行。

最后 i 与 2i 和 2i+1 链接,类比线段树的建树方式。

答案对 n 取模,并特判 =0 的情况。

    inline void solve(){
        n=read();
        f(i,1,n){
            int x=(i<<1|1),y=(i<<1);
            x%=n,y%=n;
            if(!x) x=n;
            if(!y) y=n; 
            cout<<x<<" "<<y<<endl;
        } 
        return;
    }