http://acm.hdu.edu.cn/showproblem.php?pid=3791

【注意】

是看树的形态是否一样,而不是中序遍历的结果

【Accepted】

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue> using namespace std;
const int maxn=(<<)+;
char str[];
int num1[maxn];
int num2[maxn];
int len1,len2;
int n;
void build1(){
for(int i=;i<len1;i++){
int cur=;
while(num1[cur]!=-){
if(str[i]-''>num1[cur]){
cur=(cur<<)+;
}else{
cur=cur<<;
}
}
num1[cur]=str[i]-'';
}
}
void build2(){
for(int i=;i<len2;i++){
int cur=;
while(num2[cur]!=-){
if(str[i]-''>num2[cur]){
cur=(cur<<)+;
}else{
cur=cur<<;
}
}
num2[cur]=str[i]-'';
}
}
bool flag;
int main(){
while(scanf("%d",&n)&&n){
memset(num1,-,sizeof(num1));
scanf("%s",str);
len1=strlen(str);
build1();
// for(int i=1;i<=len1;i++){
// cout<<num1[i]<<" ";
// }
// cout<<endl;
for(int i=;i<n;i++){
scanf("%s",str);
flag=true;
memset(num2,-,sizeof(num2));
len2=strlen(str);
if(len1!=len2){
puts("NO");
continue;
}
build2();
for(int j=;j<maxn;j++){
if(num1[j]!=num2[j]){
flag=false;
break;
}
}
if(flag) puts("YES");
else puts("NO");
}
}
return ;
}

【二叉搜索树】hdu 3791的更多相关文章

  1. HDU 3791 二叉搜索树 (数据结构与算法实验题 10.2 小明) BST

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=3791 中文题不说题意. 建立完二叉搜索树后进行前序遍历或者后序遍历判断是否一样就可以了. 跟这次的作业第 ...

  2. HDU 3791 二叉搜索树

    二叉搜索树 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  3. HDU 3791 二叉搜索树 题解

    Problem Description 推断两序列是否为同一二叉搜索树序列   Input 開始一个数n,(1<=n<=20) 表示有n个须要推断,n= 0 的时候输入结束. 接下去一行是 ...

  4. hdu 3791:二叉搜索树(数据结构,二叉搜索树 BST)

    二叉搜索树 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submiss ...

  5. hdu 3791 二叉搜索树(数据结构)

    二叉搜索树 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. HDU - 3791 建立二叉搜索树

    题意: 给定一个序列,下面又有n个序列,判断这个序列和其他序列是否为同一个二叉树(同一序列数字各不相同) 思路: 首先讲将一个序列建立成二叉搜索树,然后将其他序列也建立二叉搜索树,两个树进行前序遍历, ...

  7. hdu 3999 The order of a Tree (二叉搜索树)

    /****************************************************************** 题目: The order of a Tree(hdu 3999 ...

  8. HDU 3999 The order of a Tree 二叉搜索树 BST

    建一个二叉搜索树,然后前序输出. 用链表建的,发现很久没做都快忘了... #include <cstdio> #include <cstdlib> struct Node{ i ...

  9. HDU 3179 二叉搜索树(树的建立)

    二叉搜索树 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  10. HDU-3719 二叉搜索树

    http://acm.hdu.edu.cn/showproblem.php?pid=3791 用数组建立二叉树: 二叉搜索树 Time Limit: 2000/1000 MS (Java/Others ...

随机推荐

  1. poj 2411 Mondriaan's Dream (轮廓线DP)

    题意:有一个n*m的棋盘,要求用1*2的骨牌来覆盖满它,有多少种方案?(n<12,m<12) 思路: 由于n和m都比较小,可以用轮廓线,就是维护最后边所需要的几个状态,然后进行DP.这里需 ...

  2. tomcat配置 —— 各个目录的作用

    tomcat各目录(文件)作用 tomcat-7.0.50解压版,主目录一览: 我们可以看到主目录下有bin,conf,lib,logs,temp,webapps,work 7个文件夹,下面对他们分别 ...

  3. 通过例子理解 k8s 架构【转】

    为了帮助大家更好地理解 Kubernetes 架构,我们部署一个应用来演示各个组件之间是如何协作的. 执行命令 kubectl run httpd-app --image=httpd --replic ...

  4. numpy.random.randint

    low.high.size三个参数.默认high是None,如果只有low,那范围就是[0,low).如果有high,范围就是[low,high). >>> np.random.ra ...

  5. 如何关闭OSX 10.11 SIP (System Integrity Protection)

    http://www.jianshu.com/p/0572336a0771 注意:SIP功能是Apple在OSX上推出的系统完整性保护功能,对于普通MAC用户来说是一项安全保护功能,如果不了解他的作用 ...

  6. Spring启动流程—源码解读

    https://blog.csdn.net/yangliuhbhd/article/details/80790761 Spring的AbstractApplicationContext的refresh ...

  7. Windows MinGW 64-bit boost 踩坑

    >g++ -Wall -shared -g -DBUILD_DLL main.cpp -ID:\gcc\boost\include\boost-1_69 -LD:\gcc\boost\lib - ...

  8. 解读tensorflow之rnn【转】

    转自:https://blog.csdn.net/mydear_11000/article/details/52414342 from: http://lan2720.github.io/2016/0 ...

  9. Django项目部署:使用uwsgi和nginx的方式

    一.背景 前两天制作的个人博客网站基本完工,大致功能具备.但是在部署环节却也处处碰壁,这里也来总结以下,以备将来不时查看以及完善. 二.前提 2.1 需要的知识 django Django是一个基于p ...

  10. 【Git版本控制】Git使用教程

    1.Git的综述 SVN是集中式版本控制系统,版本库集中放在中央服务器上,而干活时用的都是自己的电脑,所以首先要从中央服务器哪里得到最新的版本,然后干活,干完后,需要把自己做完的活推送到中央服务器.集 ...