栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 3170 7 Levels of Binary S...

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 3170 7 Levels of Binary S...

#include <stdio.h>  #include <iostream>  #include <string>  #include <memory.h>  #include <algorithm>  #include <vector>  #include <queue>  using namespace std;  int num[256];  vector<int> result;  struct node   {      int data;      struct node *left,*right;  }*Head;  void insert(int elem,struct node * & p)  {      if( p == NULL )      {          p = (struct node*)malloc(sizeof(struct node));          p->data = elem;          p->left = p->right = NULL;          return ;      }      if( elem > p->data )          insert(elem,p->right);      elseinsert(elem,p->left);  }  void postorder(struct node *p)  {      if(p==NULL) return;      else      {          postorder(p->left);          postorder(p->right);          result.push_back(p->data);      }  }  int main(void)  {      int n,l;      int a,b,c;      queue<int> start,index,end;      while(scanf("%d",&n)!=EOF)      {          memset(num,0,sizeof(num));          result.clear();          for(int i=0;i<n;++i)   scanf("%d",&num[i]);          sort(num,num+n);          scanf("%d",&l);          if (n==1)          {   printf("%dn",num[0]);   continue;          }          scanf("%d %d",&a,&c);          start.push(0);          index.push(a);          end.push(a+c);          while(!start.empty())          {   a=start.front();   b=index.front();   c=end.front();   start.pop(),index.pop(),end.pop();   insert(num[b],Head);   if(b-a>0)   {       int temp1=0,temp2=0;       if(b-a>1)scanf("%d %d",&temp1,&temp2);       start.push(a);index.push(a+temp1);end.push(a+temp1+temp2);   }   if(c-b>0)   {       int temp1=0,temp2=0;       if(c-b>1)scanf("%d %d",&temp1,&temp2);       start.push(b+1);index.push(b+1+temp1);end.push(b+1+temp1+temp2);   }          }          postorder(Head);          printf("%d",result[0]);          for(int i=1;i<n;++i)   printf(" %d",result[i]);          Head=NULL;          printf("n");      }      return 0;  }
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/373697.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号