zoukankan      html  css  js  c++  java
  • codeforces 675D Tree Construction set

    转自:http://blog.csdn.net/qwb492859377/article/details/51447350

    #include <stdio.h>
    #include <iostream>
    #include <algorithm>
    #include <string.h>
    #include <stdlib.h>
    #include <map>
    #include <queue>
    #include <set>
    using namespace std;
    typedef long long LL;
    const int INF=0x3f3f3f3f;
    const int N=1e5+5;
    typedef pair<int,int> pii;
    set<pii>s;
    int fa[N];
    bool l[N],r[N];
    int main(){
        int n;
        scanf("%d",&n);
        set<pii>::iterator it1,it2;
        pii tmp;
        scanf("%d",&tmp.first),tmp.second=1;
        s.insert(tmp);
        for(int i=2;i<=n;++i){
          scanf("%d",&tmp.first);
          tmp.second=i;
          it2=s.lower_bound(tmp);
          if(it2==s.end()){
              it1=it2;it1--;
            fa[i]=(*it1).first;
            r[(*it1).second]=true;
          }
          else {
            if(it2==s.begin()){
              fa[i]=(*it2).first;
              l[(*it2).second]=true;
            }
            else{
              it1=it2;it1--;
              if(!r[(*it1).second]){
                fa[i]=(*it1).first;
                r[(*it1).second]=true;
              }
              else{
                fa[i]=(*it2).first;
                l[(*it2).second]=true;
              }
            }
          }
          s.insert(tmp);
        }
        for(int i=2;i<n;++i)
          printf("%d ",fa[i]);
        printf("%d
    ",fa[n]);
        return 0;
    }
    View Code
  • 相关阅读:
    PHP设计模式
    秒杀方案
    lua 安装
    docker 相关命令
    dockerfile
    JS工具对象 DATE 方法
    JS工具对象 Array
    JS工具对象 String 10种常用 方法
    工具对象
    JS工具对象Math 7个常用 方法
  • 原文地址:https://www.cnblogs.com/shuguangzw/p/5534283.html
Copyright © 2011-2022 走看看