zoukankan      html  css  js  c++  java
  • BST | 1043 BST树与镜像BST树的判断

    较为简单。小于大于的都走一遍就可以AC了

    #include <stdio.h>
    #include <memory.h>
    #include <math.h>
    #include <string>
    #include <vector>
    #include <set>
    #include <stack>
    #include <queue>
    #include <algorithm>
    #include <map>
    
    
    #define I scanf
    #define OL puts
    #define O printf
    #define F(a,b,c) for(a=b;a<c;a++)
    #define FF(a,b) for(a=0;a<b;a++)
    #define FG(a,b) for(a=b-1;a>=0;a--)
    #define LEN 1010
    #define MAX (1<<30)-1
    #define V vector<int>
    
    using namespace std;
    
    int pre[LEN];
    vector<int> post;
    bool isMirror=0;
    int n;
    
    void set_post(int a,int b){
        if(a>b)return;
        if(a!=b){
            int i=a+1;
            if(isMirror)
                while(i<=b && pre[i]>=pre[a]) i++;
            else
                while(i<=b && pre[i]<pre[a]) i++;
            int j=i;
            if(isMirror)
                while(j<=b && pre[j]<pre[a]) j++;
            else
                while(j<=b && pre[j]>=pre[a]) j++;
            set_post(a+1,i-1);
            set_post(i,j-1);
        }
        post.push_back(pre[a]);
    }
    
    int main(){
    //    freopen("1043_3.txt","r",stdin);
        I("%d",&n);
        int i;
        FF(i,n) I("%d",&pre[i]);
        set_post(0,n-1);
        bool isOK=1;
        if(post.size()!=n){
            post.clear();
            isMirror=1;
            set_post(0,n-1);
            if(post.size()!=n)
                isOK=0;
        }
        if(isOK){
            puts("YES");
            FF(i,n){
                O("%d",post[i]);
                if(i!=n-1)
                    O(" ");
            }
        }else
            puts("NO");
        return 0;
    }
  • 相关阅读:
    Python with语句和过程抽取思想
    HTML DOM 学习
    暴力破解( Hydra | Medusa)
    CSRF漏洞原理浅谈
    文件包含漏洞原理浅探
    JavaScript BOM学习
    PHP命令执行漏洞初探
    一段思考
    文件上传解析漏洞
    谈谈Javascript的this关键字(this is not this)
  • 原文地址:https://www.cnblogs.com/TQCAI/p/8530516.html
Copyright © 2011-2022 走看看