树的最小表示法 poj1635 Subway tree systems
来源:互联网 发布:蜀山战纪 网络结局 编辑:程序博客网 时间:2024/05/02 04:33
传送门:点击打开链接
题意:有根树,0表示远离根节点,1表示接近根节点,一条边只访问一次。现在告诉你两种访问方式,问这两棵树是否同构异形。
思路:从下向上把子树排序,这样向上,最后表示出来的就是最小表示的了,那么就有序了,就可以直接比较字符串就能判断两棵树是否相同。
#include<map>#include<set>#include<cmath>#include<ctime>#include<stack>#include<queue>#include<cstdio>#include<cctype>#include<string>#include<vector>#include<cstring>#include<iostream>#include<algorithm>#include<functional>#define fuck(x) cout<<"["<<x<<"]"#define FIN freopen("input.txt","r",stdin)#define FOUT freopen("output.txt","w+",stdout)using namespace std;typedef long long LL;const int MX = 1e4 + 5;char S[MX];string solve(int l, int r) { int cnt = 0, p = l; vector<string>tmp; for(int i = l; i <= r; i++) { if(S[i] == '0') cnt++; else cnt--; if(cnt == 0) { tmp.push_back(solve(p + 1, i -1)); p = i + 1; } } sort(tmp.begin(), tmp.end()); string ret = "0"; for(int i = 0; i < (int)tmp.size(); i++) { ret += tmp[i]; } return ret + "1";}int main() { int T; //FIN; scanf("%d", &T); while(T--) { scanf("%s", S); string a = solve(0, strlen(S) - 1); scanf("%s", S); string b = solve(0, strlen(S) - 1); if(a == b) printf("same\n"); else printf("different\n"); } return 0;}
0 0
- 树的最小表示法 poj1635 Subway tree systems
- Subway tree systems - POJ 1635 树的最小表示法
- poj1635 - Subway tree systems
- POJ1635 Subway tree systems
- ZJU 1990 Subway tree systems - 树的最小表示
- pku 1635 Subway tree systems(树的同构,最小表示)
- ZJU 1990 Subway tree systems - 树的最小表示
- ZJU 1990 Subway tree systems - 树的最小表示
- Poj 1635 Subway tree systems (树的最小表示)
- ZJU 1990 Subway tree systems - 树的最小表示
- POJ1635(Subway tree systems)
- POJ 1635 Subway tree systems 树的Hash 或 树的最小表示法
- poj 1635 Subway tree systems 判断树的同构 树的最大最小表示法模板
- POJ-1635:Subway tree systems(树的最小表示法)
- [POJ1635]Subway tree systems 判断有根树的同构 有根树哈希
- Sicily 1064. Subway Tree Systems[数的最小表示]
- poj1635 树的最小表示
- HDU 1954Subway tree systems(树的同构,树的最小表示)
- Heritrix使用UTF-8编码格式存储文件
- Java 操作剪切板
- SQLSERVER 数据库日志文件收缩
- eclipse优化设置,自动提示篇
- "转义
- 树的最小表示法 poj1635 Subway tree systems
- asp.net取request 集合
- nginx学习3——nginx进程
- [Javascript] 继承 (原型继承, 类继承)
- 这有相当多的优势。
- android局域网通信(三)
- Android 基础代码实例:音频 均衡器 示波器 声场 等
- openGL ES在VS2012中配置遇到的应用程序无法正常启动0xc000007b解决方法
- ArcEngine 专题图关键代码