码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 3791

时间:2014-11-05 19:06:49      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   for   sp   

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

建立二叉树,对比是否相同

bubuko.com,布布扣
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

#define lson rt<<1
#define rson rt<<1|1

int tree[2500],ttree[2500];

char str[25];

int main(){
    int n;
    while(~scanf("%d",&n),n){
        memset(tree,-1,sizeof(tree));
        scanf("%s",str);
        int len=strlen(str);
        for(int i=0;i<len;i++){
            int a=str[i]-0;
            int rt=1;
            while(tree[rt]!=-1){
                if(a<tree[rt])rt=lson;
                else rt=rson;
            }
            tree[rt]=a;
        }
        for(int i=0;i<n;i++){
            scanf("%s",str);
            len=strlen(str);
            memset(ttree,-1,sizeof(ttree));
            for(int j=0;j<len;j++){
                int a=str[j]-0;
                int rt=1;
                while(ttree[rt]!=-1){
                    if(a<ttree[rt])rt=lson;
                    else rt=rson;
                }
                ttree[rt]=a;
            }
            int flag=1;
            for(int j=1;j<2500;j++)
                if(tree[j]!=ttree[j]){
                    flag=0;
                    break;
                }
            if(flag)puts("YES");
            else puts("NO");
        }
    }
    return 0;
}
View Code

 

HDU 3791

标签:style   blog   http   io   color   ar   os   for   sp   

原文地址:http://www.cnblogs.com/xiaohongmao/p/4076809.html

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