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) (水 ...
随机推荐
- 挂载mount、卸载umount、挂载光盘U盘
mount [root@localhost ~]# mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel) ...
- dispatch_sync和dispatch_async的区别
dispatch_sync 线程同步.dispatch_async线程异步 比如 //同步 dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE ...
- java 异常处理机制(java 编程思想)
一.概念 "异常"这个词有"我对此感到意外"的意思.问题出现了,你也许并不清楚该如何处理,但你的确知道不应该置之不理:你要停下来,看看是不是有别人或在别的地方, ...
- CPU31X-2DP通过DP网络连接远程IO站
一.远程IO站介绍 二.该DP网络系统结构 三.组态DP主站 1.组态机架硬件配置 2.设置profibus属性,主站地址为2,如下图 3.完成主站组态 四.组态远程IO从站ET200M 1.接口模块 ...
- DeepLearning.ai学习笔记(三)结构化机器学习项目--week2机器学习策略(2)
一.进行误差分析 很多时候我们发现训练出来的模型有误差后,就会一股脑的想着法子去减少误差.想法固然好,但是有点headlong~ 这节视频中吴大大介绍了一个比较科学的方法,具体的看下面的例子 还是以猫 ...
- xamarin android如何监听单击事件
在xamarin android单击事件是最基础的事情,看过菜鸟上的android教程时,java写的都是监听事件,为一个按钮,单选按钮.多选按钮的单击事件有三种,前面两种用的非常普遍,也很简易,我这 ...
- php date函数
PHP星期几获取代码: 1 date("l"); 2 //data就可以获取英文的星期比如Sunday 3 date("w"); 4 //这个可以获取数字星期比 ...
- django2 快速安装指南
django2 快速安装指南 1. 安装 作为一个 Python Web 框架,Django需要Python的支持.请参阅 我可以在Django中使用哪些Python版本?了解详情.Python包含一 ...
- jq 中each的用法 (share)
each的使用方法 在jQuery里有一个each方法,用起来非常的爽,不用再像原来那样写for循环,jQuery源码里自己也有很多用到each方法.其实jQuery里的each方法是通过js里的ca ...
- C# DataGridView 的UserDeletingRow事件,删除
DialogResult dr = MessageBox.Show("确认删除记录吗?", "提示", MessageBoxButtons.YesNo); ...