ZOJ3602:Count the Trees
我是在neuqvj上交的这题:http://vj.acmclub.cn/problem/viewProblem.action?id=17848
本来是挺容易的树同构题,可是节点数比较多,愣是把普通hash卡掉了(出题人麻烦您过来一下)
只能用map映射一下,给每个状态一个标号,而状态的表示是它两个儿子的标号。
#include<map>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MN 110001
#define ll long long
#define fi first
#define se second
using namespace std; int read_p,read_ca,read_f;
inline int read(){
read_p=;read_ca=getchar();read_f=;
while(read_ca<''||read_ca>'') read_f=read_ca=='-'?-:read_f,read_ca=getchar();
while(read_ca>=''&&read_ca<='') read_p=read_p*+read_ca-,read_ca=getchar();
return read_p*read_f;
}
const int HA=1e6+;
int T,n,m,ha[MN],a,b,L[MN],R[MN],nm=,mmh[][MN];
ll MMH;
map<pair<int,int>,int>mp;
int dfs(int x,int mmh[]){
int MMH;
pair<int,int> now=make_pair(L[x]==-?:dfs(L[x],mmh),R[x]==-?:dfs(R[x],mmh));
if (mp.find(now)==mp.end()) MMH=mp[now]=++nm;else MMH=mp[now];
mmh[MMH]++;
return MMH;
}
inline void work(int n,int mmh[]){
for (int i=;i<=n;i++) L[i]=read(),R[i]=read();
dfs(,mmh);
}
int main(){
T=read();
for (int i=;i<MN;i++) ha[i]=rand()%HA;
while (T--){
nm=;mp.clear();
memset(mmh,,sizeof(mmh));
n=read();m=read();MMH=;
work(n,mmh[]);
work(m,mmh[]);
for (int i=;i<=nm;i++) MMH+=1LL*mmh[][i]*mmh[][i];
printf("%lld\n",MMH);
}
}
C++ 190 8608
ZOJ3602:Count the Trees的更多相关文章
- zjuoj 3602 Count the Trees
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3602 Count the Trees Time Limit: 2 Seco ...
- Count the Trees[HDU1131]
Count the Trees Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Uva 10007 / HDU 1131 - Count the Trees (卡特兰数)
Count the Trees Another common social inability is known as ACM (Abnormally Compulsive Meditation) ...
- TZOJ 4292 Count the Trees(树hash)
描述 A binary tree is a tree data structure in which each node has at most two child nodes, usually di ...
- HDU 1131 Count the Trees 大数计算
题目是说给出一个数字,然后以1到这个数为序号当做二叉树的结点,问总共有几种组成二叉树的方式.这个题就是用卡特兰数算出个数,然后因为有编号,不同的编号对应不同的方式,所以结果是卡特兰数乘这个数的阶乘种方 ...
- UVa 10007 - Count the Trees(卡特兰数+阶乘+大数)
题目链接:UVa 10007 题意:统计n个节点的二叉树的个数 1个节点形成的二叉树的形状个数为:1 2个节点形成的二叉树的形状个数为:2 3个节点形成的二叉树的形状个数为:5 4个节点形成的二叉树的 ...
- uva 10007 Count the Trees
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- HDU 1131 Count the Trees
卡特兰数再乘上n的阶乘 #include<iostream> #include<cstdio> using namespace std; #define base 10000 ...
- 2012-2014 三年浙江 acm 省赛 题目 分类
The 9th Zhejiang Provincial Collegiate Programming Contest A Taxi Fare 25.57% (166/649) (水 ...
随机推荐
- 环境变量配置文件,本地登录前提示信息/etc/issue
让配置文件立即生效:source 配置文件 或 . 配置文件 /etc/profile 例:定义了HISTSIZE=1000 /etc/profile.d/*.sh /etc/bashrc ~/.ba ...
- 数值函数ROUND(四舍五入),TRUNC(不四舍五入),MOD
- cell的复用机制
以下全部都是转载自别人的博客:http://blog.sina.com.cn/s/blog_9c3c519b01016aqu.html 转自:http://www.2cto.com/kf/201207 ...
- HDU4992 求所有原根
Primitive Roots Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- C#常用单词
C#语言需要的一些英语注释 About -----关于 abstract -----抽象的 Abstract ------抽象的 Accept -----接受 activat -----活跃 add ...
- 浅谈OGNL表达式
OGNL(Object-Graph Navigation Language):对象视图导航语言 ${user.addr.name}这样的写法就叫对象视图导航 OGNL不仅可以视图导航,支持EL表达式更 ...
- 前端MVC Vue2学习总结(六)——axios与跨域HTTP请求、Lodash工具库
一.axios Vue更新到2.0之后宣告不再对vue-resource更新,推荐使用axios,axios是一个用于客户端与服务器通信的组件,axios 是一个基于Promise 用于浏览器和 no ...
- 搭建非域AlwaysOn win2016+SQL2016
搭建非域AlwaysOn win2016+SQL2016 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www.cnblogs.co ...
- http1.0 的哑代理问题
感觉这就和回字的四种写法一样,并无卵用 原以为http1.1的新特性是提供了keep-alive,后来才知道,keep-alive选项http1.1已经不支持了,http1.1对该功能进行了改版 关于 ...
- Office 365也是.NET Core应用开发新战场
最近有幸阅读了陈希章花了一年时间为国内开发者贡献的<Office 365 开发入门指南>. 虽然早期接触过SharePoint的开发,2007年之后就再也没有接触SharePoint的开发 ...