• 【UNR #1】奇怪的线段树


    SOL:

       好像可以贪心啊,一颗树的左儿子的右儿子和右儿子的左儿子合并。其他递归处理。

    #pragma GCC optimize("-Ofast")
    #include<bits/stdc++.h>
    using namespace std;
    int n,lx,rx,mx,ux,ans;
    int sol(int op,int l,int r,int &lx,int &rx,int &mx,int &ux) {
        int x; scanf("%d",&x);
        if (!op&&x) {puts("OwO");exit(0);}//it->fa=white && it=black is impossible
        if (l<r){
            int mid,ll,rr,l1,r1,l2,r2,m1,m2,u1,u2;
            scanf("%d",&mid);
            ll=sol(x,l,mid,l1,r1,m1,u1);
            rr=sol(x,mid+1,r,l2,r2,m2,u2);
            int mn=min(r1,l2); //it->son[0]->son[1] and it->son[1]->son[0] merge fisrt
            rx=r1-mn,lx=l2-mn; ans+=mn; ux=mn;
            if (!ll) {ans+=lx; lx=0; } // it->son[0] can't merge
            if (!rr) {ans+=rx; rx=0; }
            if (m1&&!l2) {
                if (u2) {u2--; ans--; ++lx; ++rx;}// as the father of seq so cancel the hypothesis
                else ++lx;
            } 
            if (m2&&!r1) {
                if (u1) {u1--; ans--; ++lx; ++rx;}
                else ++rx;
            }
            if (!ll&&!rr) mx=x; else mx=0; //whether this seq can merge
            lx+=l1; rx+=r2;
            if (ll) ux+=u2; if (rr) ux+=u1; // ux's mean is the number of merged seq 
        }  else {lx=rx=ux=0; mx=x;}
        return x;
    }
    signed main () {
    //    freopen("u2.in","r",stdin);
        scanf("%d",&n);
        sol(1,1,n,lx,rx,mx,ux);
        printf("%d",ans+lx+rx+mx);
        return 0;
    }
  • 相关阅读:
    织梦系统的安装与详细信息
    js 报错 :object is not a function
    css3中动画animation的应用
    js 中 setTimeout()的用法
    CSS3 Gradient-CSS3渐变
    css3 transform 变形
    CSS3 transition 属性
    只要有人的地方,世界就不是冰冷的。
    CSS层
    css区块定位之浮动与清除属性
  • 原文地址:https://www.cnblogs.com/rrsb/p/9335776.html
Copyright © 2020-2023  润新知