码迷,mamicode.com
首页 > 编程语言 > 详细

#572. 完全二叉排序树

时间:2019-09-05 23:14:10      阅读:371      评论:0      收藏:0      [点我收藏+]

标签:stdout   else   def   string   span   nbsp   char   color   mes   

题面: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("\nno\n");
53     else printf("\nyes\n");
54     return 0;
55 }

 

#572. 完全二叉排序树

标签:stdout   else   def   string   span   nbsp   char   color   mes   

原文地址:https://www.cnblogs.com/hahaha2124652975/p/11470267.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!