求树上点权积为立方数的路径数. 显然,分解质因数后,若所有的质因子出现的次数都%3==0,则该数是立方数. 于是在模意义下暴力统计即可. 当然,为了不MLE/TLE,我们不能存一个30长度的数组,而要压成一个long long. 存储状态用map即可,貌似哈希表可以随便卡掉……? 手动开栈……当然这样有可能MLE,所以还得改一些BFS…… <法一>map: #pragma comment(linker, "/STACK:1024000000,1024000000") #in…
The country Tom living in is famous for traveling. Every year, many tourists from all over the world have interests in traveling there. There are n provinces in the country. According to the experiences from the tourists came before, every province h…
人生的第一道树分治,要是早点学我南京赛就不用那么挫了,树分治的思路其实很简单,就是对子树找到一个重心(Centroid),实现重心分解,然后递归的解决分开后的树的子问题,关键是合并,当要合并跨过重心的两棵子树的时候,需要有一个接近O(n)的方法,因为f(n)=kf(n/k)+O(n)解出来才是O(nlogn).在这个题目里其实就是将第一棵子树的集合里的每个元素,判下有没符合条件的,有就加上,然后将子树集合压进大集合,然后继续搞第二棵乃至第n棵.我的过程用了map,合并是nlogn的所以代码速度颇…
题意:给一个N个带权节点的树,权值以给定的K个素数为因子,求路径上节点乘积为立方数的路径条数 思路:立方数的性质是每个因子的个数为3的倍数,那么每个因子只需要保存0-2三个状态即可,然后路径就可以转化为一个K位3进制数,点分治后,便可以用一个map来查询路径经过根的答案.代码与上一题(poj1741)类似:http://www.cnblogs.com/jklongint/p/4960052.html #pragma comment(linker,"/STACK:10240000,10240000…
3.10 Go Map哈希表 map是key-value类型数据结构,读作(哈希表.字典),是一堆未排序的键值对集合. map是引用类型,使用make函数或者初始化表达式创建. map的key必须是支持相等运算符==.!=的类型,如int.bool.channel.string.pointer.array.sruct.interface. 通常map的key是int.string map的value可以是任意类型,没有限制,通常是int.float.string.struct 2. map声明…
Cube number on a tree Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submission(s): 1628    Accepted Submission(s): 382 Problem Description The country Tom living in is famous for traveling. Every year, man…
题意 : 给你一棵树 . 树的每一个结点都有一个权值 . 问你有多少条路径权值的乘积是一个全然立方数 . 题目中给了你 K 个素数 ( K <= 30 ) , 全部权值都能分解成这k个素数 思路 : 一个全然立方数的素因子个数都是三的倍数 , 所以我们仅仅要求各个素数的个数即可了 , 而且我们仅仅关心个数对三的余数 所以我们能够用一个 长整形来表示每一个结点到根的各个素因子的个数( 三进制压缩 ) . 只是由于用位运算会快一点 , 所以我用了四进制.即每两位表示一个素因子的个数 . 中间合并的时…
divide and conquer on tree. #include <map> #include <vector> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> using namespace std; const int N = 5e4+10; const int K = 32; typedef long long LL;…
以下注释的源代码都在memcached项目的assoc.c文件中 /* how many powers of 2's worth of buckets we use */ unsigned int hashpower = HASHPOWER_DEFAULT; /* 哈希表bucket的级别,(1<<hashpower) == bucket的个数 */ /* Main hash table. This is where we look except during expansion. */ /*…
13.2 Compare and contrast a hash table and an STL map. How is a hash table implemented? If the number of inputs is small, which data structure options can be used instead of a hash table? 这道题让我们比较哈希表和STL中的map数据结构,在遇到这道题之前,我一直以为map就是c++中的哈希表呢,原来是不同的啊-…