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) (水 ...
随机推荐
- C# 委托与事件详解(二)
什么是事件?EVENT?点击事件?加载事件?一连串的模糊的概念冲击着我们弱小的脑袋 那我们首先来看一下比较正统的感念吧: 事件是类在发生其关注的事情时用来提供通知的一种方式. 事件的发生一般都牵扯2个 ...
- 其他函数:值为NULL时的默认值NVL,DECODE
NVL(列,默认数字值),此函数返回值为数值型,非NULL时返回原始值,NULL时返回默认数字值. DECODE:
- Node.js前言
最近在学Node.js,所以学到一点东西就更新在上面吧,如果有错误,欢迎大家指正.
- iOS 蓝牙开发资料记录
一.蓝牙基础认识: 1.iOS蓝牙开发: iOS蓝牙开发:蓝牙连接和数据读写 iOS蓝牙后台运行 iOS关于app连接已配对设备的问题(ancs协议的锅) iOS蓝牙空中 ...
- ES6中Promise对象个人理解
Promise是ES6原生提供的一个用来传递异步消息的对象.它减少了传统ajax金字塔回调,可以将异步操作以同步操作的流程表达出来使得代码维护和可读性方面好很多. Promise的状态: 既然是用来传 ...
- thinkphp 3.1.3 redis 只能读取 无法写入的问题
找到thinkphp的目录 thinkphp\Extend\Driver\Cache 下面的Redis 大概在81行足有 // if(is_int($expire)) { // redis ...
- Xamarin.android 重写axml控件
https://www.cnblogs.com/lonelyxmas/p/5632694.html <Laco: 用来用引指定的控件 android:layout_widt ...
- arm-linux-objdump反汇编使用指南
一. arm-linux-objdump常用来显示二进制文件信息,常用来查看反汇编代码 二. 常用选项: 1.-b bfdname 指定目标码格式 2.-disassemble或者-d 反汇编 ...
- 转: 谈JAVA_OPTS环境变量不起作用
谈JAVA_OPTS环境变量不起作用 2016-6-14 11:12 最近在处理运行一个java应用时,老是出现java.lang.OutOfMemoryError: Java heap space. ...
- socket对象放在一个datagridview的row的tag里面在拿出来 为什么是已释放
socket对象放在一个datagridview的row的tag里面在拿出来 为什么是已释放