POJ 1635 Subway tree systems (BSOJ 1092)
来源:互联网 发布:火狐淘宝无法登陆 编辑:程序博客网 时间:2024/06/16 04:01
题目大意:求两个有根数是否同构
方法:
1.from nodgd %%%%% 来自某次noip模拟赛的题解
2.最小表示法 没看懂……
3.利用hash判断
国家集训队论文《Hash在信息学竞赛中的一类应用》中有讲解。
直接上代码
#include<iostream>#include<iomanip>#include<cstring>#include<cmath>#include<cstdio>#include<algorithm>using namespace std;const int mod=160883,mul=9110;int T,a[10005],b[10005];string s1,s2;int dfs(int l,int r,int a[]){if(l+1==r)return 1;int t,i,j,tot=0,tmp[3005],ret=1908;for(i=l;i<=r;i=j+1){t=0;for(j=i;j<=r;j++){t+=a[j];if(t==0)break;}tmp[++tot]=dfs(i+1,j-1,a);}sort(tmp+1,tmp+tot+1);for(int i=1;i<=tot;i++)ret=((ret*mul)^tmp[i])%mod;return ret;}int main(){cin>>T;while(T--){cin>>s1>>s2;int l1=s1.length(),l2=s2.length();s1=' '+s1,s2=' '+s2;for(int i=1;i<=l1;i++) if(s1[i]=='0')a[i]=1; else a[i]=-1;for(int i=1;i<=l1;i++) if(s2[i]=='0')b[i]=1; else b[i]=-1;if(dfs(1,l1,a)==dfs(1,l2,b))cout<<"same\n";else cout<<"different\n";}return 0;}
2 0
- POJ 1635 Subway tree systems (BSOJ 1092)
- 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 判断是否是同构树
- 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(判断两个有根树是否同构)-哈希法
- Linux线程编程 - 线程同步机制之互斥锁
- 图形验证码的实现
- ListView加载更多的最简单实现方式
- DispatchMessage - synchronous or asynchronous
- 简单--> js 计算器
- POJ 1635 Subway tree systems (BSOJ 1092)
- 线程池
- 避免带有变长参数的方法重载
- c# 入门级Java对比 7 —— 委托
- Vijos P1118 统计单词个数(动态规划,划分型DP,字符串)
- 标准库类型vector
- Android开发学习之添加StatusBarNotification(状态栏通知)
- eclipse中java项目的build path详解
- python两个list转dict