hdu3791 搜索二叉树 (最基本的树)
View Code
1 #include<stdio.h> 2 #include<string.h> 3 int tree[1050]; 4 int tree1[1050]; 5 char s[12]; 6 int main() 7 { 8 int t,i; 9 while(scanf("%d",&t),t) 10 { 11 scanf("%s",s); 12 memset(tree,-1,sizeof(tree)); 13 for(i=0;s[i];i++) 14 { 15 int c=s[i]-'0'; 16 int j=1; 17 while(tree[j]!=-1) 18 { 19 if(c<tree[j]) 20 j=j*2; 21 else 22 j=j*2+1; 23 } 24 tree[j]=c; 25 } 26 while(t--) 27 { 28 scanf("%s",s); 29 memset(tree1,-1,sizeof(tree1)); 30 for(i=0;s[i];i++) 31 { 32 int c=s[i]-'0'; 33 int j=1; 34 while(tree1[j]!=-1) 35 { 36 if(c<tree1[j]) 37 j=j*2; 38 else j=j*2+1; 39 } 40 tree1[j]=c; 41 } 42 for(i=1;i<1024&&tree[i]==tree1[i];i++); 43 if(i==1024)printf("YES\n"); 44 else printf("NO\n"); 45 } 46 } 47 return 0; 48 49 }
作者: 点A点C
出处: http://www.cnblogs.com/ACshasow/>
关于作者:游戏开发、算法研究,请多多赐教!
本文版权归作者(点A点C)和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出, 原文链接 如有问题, 可邮件(572779130@qq.com)咨询.