nyoj 1278 Prototypes analyze
来源:互联网 发布:linux设置javahome 编辑:程序博客网 时间:2024/05/22 14:28
点击打开链接
题意: 让你建n个排序二叉树。 问你结构不同的树有多少。
题解: 建树,暴力比较树,
其实我开始想先全部建树,然后把所有数先序遍历一遍,记录遍历的左右子节点的顺序,存字符串中,用map计数。
后来这个都很快, 学习了,树学的好差劲呀。
#include<cstdio>#include<queue>#include<string>#include<vector>#include<cstring>#include<map>#include<cmath>#include<algorithm>#define ll long longusing namespace std;const int maxn=10020;const int inf=0;int n,m,ff;typedef struct node{ node *left; node *right; int val;}*Tree;Tree tree[55];void builetree(Tree &p,int val){ if(p==NULL){ p=new node(); p->left=NULL; p->right=NULL; p->val=val; } if(val>p->val) builetree(p->right,val); if(val<p->val) builetree(p->left,val);}void dfs(Tree p){ if(p->left) dfs(p->left); if(p->right) dfs(p->right);}void judge(Tree t1,Tree t2){ if(t1==NULL&&t2==NULL) return ; else if(t1&&t2){ judge(t1->left,t2->left); judge(t1->right,t2->right); }else ff=0;}int main(){ int t,x; scanf("%d",&t); while(t--){ scanf("%d %d",&n,&m); for(int i=0;i<n;++i){ Tree t=NULL; for(int j=0;j<m;++j){ scanf("%d",&x); builetree(t,x); } tree[i]=t; } int ans=0,i,j; for(i=0;i<n;++i){ int f=1; for(j=i+1;j<n;++j){ ff=1; judge(tree[i],tree[j]); if(ff){f=0;break;} } if(f) ans++; } printf("%d\n",ans); } return 0;}
0 0
- nyoj 1278 Prototypes analyze
- nyoj 1278 Prototypes analyze(平衡二叉树)
- nyoj 1278 【二叉搜索树】 G: Prototypes analyze
- Prototypes analyze
- G Prototypes analyze
- 2016 acm河南省赛 G Prototypes analyze
- nyoj1278 zzuli1929 Prototypes analyze(河南省acm第九届省赛)
- ANALYZE
- 深入理解 prototypes.js
- Prototypes.js 使用
- JavaScript: Classes and Prototypes
- JavaScript Object Prototypes
- Function,Object,Prototypes,__proto__
- JavaScript Object Prototypes
- analyze使用
- analyze DDL
- Oracle analyze
- startx analyze
- Android仿淘宝头条基于TextView实现上下滚动通知效果
- 详解 Canvas.drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)
- 高效率的幂运算
- linux操作提示:“Can't open file for writing”或“operation not permitted”的解决办法
- 21. Merge Two Sorted Lists
- nyoj 1278 Prototypes analyze
- 有关时间戳的方法
- 删除永久性联系
- Quartz Job未实例化导致Spring @Autowired 注入为null
- 动作捕捉
- 第十二单元练习
- css清除浮动的三种方法
- 浅谈java并发容器ConcurrentHashMap
- Zookeeper原理