• #572. 完全二叉排序树


    题面:http://220.180.209.150:38888/problem/572

    哼,这个题目真的很简单啊。。原谅我最开始把题面看错了。。

    实际上就是呢以第一个点为树根结点,然后将每个读进来的结点比对并插入树中。

    唯一的问题呢,就是数组大小的问题。。md。。数组开100的话只有90分。。所以,自重喽~~

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<cmath>
     5 #include<queue>
     6 #include<stack>
     7 #include<deque>
     8 #include<algorithm>
     9 #define ll long long
    10 using namespace std;
    11 const int oo=0x3f3f3f3f;
    12 const int N=1005;
    13 
    14 int n,t=1;
    15 int a[N];
    16 
    17 int get(){
    18     char zy=getchar();
    19     int z=1,y=0;
    20     while(zy>'9'||zy<'0'){
    21         if(zy=='-') z=-1;
    22         zy=getchar();
    23     }
    24     while(zy>='0'&&zy<='9'){
    25         y=(y<<1)+(y<<3)+zy-'0';
    26         zy=getchar();
    27     }
    28     return z*y;
    29 }
    30 
    31 int Max(int a,int b){return a>b?a:b;}
    32 
    33 int main(){
    34     //freopen(".in","r",stdin);
    35     //freopen(".out","w",stdout);
    36     n=get();
    37     a[1]=get();
    38     for(int i=1;i<n;i++){
    39         int u=get(),l=1;
    40         while(a[l]!=0){
    41             if(a[l]>u) l*=2;
    42             else l=l*2+1;
    43         }
    44         a[l]=u;
    45         t=Max(t,l);
    46     }
    47     for(int i=1;i<=t;i++){
    48         if(a[i]){
    49             printf("%d ",a[i]);
    50         }
    51     }
    52     if(t!=n) printf("
    no
    ");
    53     else printf("
    yes
    ");
    54     return 0;
    55 }
  • 相关阅读:
    需求分析-配置软件开发的出发点
    有关tab页的
    有关菜单的
    有关树形结构的
    需求分析-新闻发布的完整需求
    需求分析-网盘类的需求分析
    需求分析-有关有关富文本编辑器的需求
    Objective-C中的instancetype和id区别
    webservice远程调试开启
    Controller之间传递数据:Block传值
  • 原文地址:https://www.cnblogs.com/hahaha2124652975/p/11470267.html
Copyright © 2020-2023  润新知