POJ 2945 trie树】的更多相关文章

用记录附加信息的val数组记录次数即可. trie的原理:每个可能出现的字目给一个编号c,那么整个树就是一个c叉树 ch[u][c]表示 节点u走c边过去之后的节点 PS:trie树还有种动态写法,使用指针和动态分配内存代替了连续的ch数组,更加节省内存. Reference:http://blog.csdn.net/architect19/article/details/8966247 #include <cstdio> #include <cstring> #include &…
Find the Clones Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 7704 Accepted: 2879 Description Doubleville, a small town in Texas, was attacked by the aliens. They have abducted some of the residents and taken them to the a spaceship orbi…
Phone List Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26559 Accepted: 8000 Description Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let's say the phone catalogue li…
生无可恋 查RE查了一个多小时.. 原因是我N define的是250500 应该是500500!!!!!!!!! 身败名裂,已无颜面对众人.. 吐槽完了 我们来说思路... 思路: 判有向图能否形成欧拉路 但是他给的是string,怎么转化成int呢? trie树! 这东西有多么优美我就不说了... 反正写起来不难. 具体的请见代码吧 // by SiriusRen #include <bitset> #include <cstdio> #define N 500500 usin…
Phone List Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 25280   Accepted: 7678 Description Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let's say the phone catalogu…
链接:poj 2513 题意:给定一些木棒.木棒两端都涂上颜色,不同木棒相接的一边必须是 同样的颜色.求能否将木棒首尾相接.连成一条直线. 分析:能够用欧拉路的思想来解,将木棒的每一端都看成一个结点 由图论知识能够知道,无向图存在欧拉路的充要条件为: ①     图是连通的. ②     全部节点的度为偶数,或者有且仅仅有两个度为奇数的结点. 图的连通性能够用并查集,由于数据比較大,所以用并查集时要压缩路径, 全部节点的度(入度和出度的和)用数组记录就好 可是25w个木棒,有50w个结点,要怎么…
题目链接:http://poj.org/problem?id=3630 题意:给你多个字符串,如果其中任意两个字符串满足一个是另一个的前缀,那么输出NO,否则输出YES 思路:简单的trie树应用,插入的过程中维护到当前节点是不是字符串这个布尔量即可,同时判断是否存在上述情况. code: #include <iostream> #include <cstdio> #include <string> #include <cstring> using name…
http://poj.org/problem?id=3764 题意 :  一颗树,每个边有个值,在树上找一条简单路径,使得这条路径上的边权异或值最大 先找到所有节点到一点的距离 , 显然dis( x , y ) = dis( z , x )^dis( z , y ) 那么把所有的距离都以二进制由高到低存到trie中 , 扫一遍每个点 , 在trie树上由高到低找某位与该点某位相反的数 , 找不到则妥协找下一位 , 如此贪心即可  写的时候超空间一次re两次,trie树的大小设置为30*n刚好,不…
一. 题目 487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 274040   Accepted: 48891 Description Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or…
Hardwood Species Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 17986   Accepted: 7138 Description Hardwoods are the botanical group of trees that have broad leaves, produce a fruit or nut, and generally go dormant in the winter.  Amer…