poj 1635 Subway tree systems
来源:互联网 发布:淘宝宠物店名字 编辑:程序博客网 时间:2024/05/21 11:30
题目链接:http://poj.org/problem?id=1635
题目大意及思路:给两种树的遍历结果,判断它们是否是同一棵树,网上都说是树的最小表示,就是说优先遍历深度大的子树,自己感觉还是理解得不是很清楚,我太水了。。做法就递归,得到子树的最小表示后,将各子树得到的序列排序即可。
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<string>#include<queue>#include<algorithm>#include<vector>#include<stack>#include<list>#include<iostream>#include<map>using namespace std;#define inf 0x3f3f3f3f#define Max 110int max(int a,int b){return a>b?a:b;}int min(int a,int b){return a<b?a:b;}int t;char str1[3010];char str2[3010];char stmp[3010];void dfs(int l,int r,char str[]){ int tmp=0,i,j; vector<string>vt; int tmpl; tmpl=l; for(i=l;i<=r;i++) { if(str[i]=='0') tmp++; if(str[i]=='1') tmp--; if(tmp==0) { dfs(tmpl+1,i-1,str); strncpy(stmp,str+tmpl,i-tmpl+1); stmp[i-tmpl+1]=0; // if(l==0) //printf("stmp %s\n",stmp); vt.push_back(stmp); tmpl=i+1; } } sort(vt.begin(),vt.end()); // int len=vt.size(); int k=l; for(i=0;i<vt.size();i++) { for(j=0;j<vt[i].size();j++) { str[k++]=vt[i][j]; } }}int main(){ scanf("%d",&t); int len1,len2; while(t--) { scanf("%s%s",str1,str2); len1=strlen(str1)-1; len2=strlen(str2)-1; dfs(0,len1,str1); // puts(""); dfs(0,len2,str2); if(strcmp(str1,str2)==0) { printf("same\n"); } else printf("different\n"); }}
- POJ 1635 Subway tree systems
- poj 1635 Subway tree systems
- poj 1635 Subway tree systems
- POJ 1635 Subway tree systems
- poj 1635 Subway tree systems
- POJ 1635 Subway tree systems
- POJ 1635 Subway tree systems
- POJ 1635 Subway tree systems
- POJ 1635 Subway tree systems
- POJ 1635 Subway tree systems (BSOJ 1092)
- poj 1635 Subway tree systems 判断是否是同构树
- Poj 1635 Subway tree systems (树的最小表示)
- poj 1635 Subway tree systems(树的同构,经典)
- Subway tree systems - POJ 1635 树的最小表示法
- poj 1635 Subway tree systems (树同构)
- poj1635 - Subway tree systems
- POJ1635 Subway tree systems
- poj-1635 Subway tree systems(判断两个有根树是否同构)-哈希法
- 解决,从 IClassFactory 为 CLSID 为 的 COM 组件创建实例失败,原因是出现以下错误: 80004005
- oracle : shared memory realm does not exist 故障解决
- OpenCV学习笔记-图像分割
- response.setContentType() ;参数说明
- Qt/MFC迁移框架(Qt/MFC Migration Framework)(转自:http://hi.baidu.com/tigerwooz/blog/item/cc6105fa65808612a)
- poj 1635 Subway tree systems
- 用jquery实现仿淘宝焦点图的动画
- 日历HTML代码
- OpenCV学习笔记-阈值化
- 利用int数 的移位操作 存储数据
- 动态库之全局对象、静态对象
- 求帮助,哪里错了?
- mysql修改表的存储引擎(myisam<=>innodb)
- 模式识别中K-近邻法的Matlab代码