hdu 1671 复习字典树】的更多相关文章

#include<cstdio> #include<iostream> #include<string> #include<cstdlib> #define maxn 10 using namespace std; struct Tri { Tri*next[maxn]; int num; }; Tri *root; void buildTri(string ss)//建树的过程是一个动态的过程 动插的过程 { Tri *p=root,*q; for;i&l…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1671 Problem 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 listed these numbers: 1. Emergenc…
传送门 题意:输入n串数字 找出是否有存在串的前缀与另一个串相同 如果存在 输出NO否则输出YES 思路:用字典树解决 标记字典树总串的结尾 查找出一个串内部是否有被标记的节点 如果有那么说明存在前缀相同的串 在插入字典树的时候判断是否存在 cin poj tle了 还是换成gets才过... AC代码: #include "iostream" #include "stdio.h" #include "string.h" using namesp…
http://acm.hdu.edu.cn/showproblem.php?pid=1979 Fill the blanks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 373    Accepted Submission(s): 155 Problem Description There is a matrix of 4*4, yo…
Repository Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 5048    Accepted Submission(s): 1739 Problem Description When you go shopping, you can search in repository for avalible merchandises b…
Repository Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 2932    Accepted Submission(s): 1116 Problem Description When you go shopping, you can search in repository for avalible merchandises…
题目 字典树,注意初始化的位置~!!位置放错,永远也到不了终点了org.... 我是用数组模拟的字典树,这就要注意内存开多少了,,要开的不大不小刚刚好真的不容易啊.... 我用了val来标记是否是同一个串分解而来的,保存的是串的编号 num记录数目. //string &replace(iterator first0, iterator last0,const_iterator first, const_iterator last); //把[first0,last0)之间的部分替换成[firs…
Input The first line of input contains an integer T indicating the total number of test cases. The first line of each test case is an integer n, indicating the number of chips produced today. The next line has n integers s1,s2,..,sn, separated with s…
three arrays \[ Time Limit: 2500 ms \quad Memory Limit: 262144 kB \] 题意 给出 \(a\),\(b\) 数组,定义数组 \(c[i] = a[i] XOR b[i]\),现在可以任意调整 \(a\) 和 \(b\) 的顺序,使得最后的 \(c\) 字典序最小. 思路 对于 \(a\) 数组和 \(b\) 数组分别建立字典树,然后从大到小在字典树上贪心构造尽量小的 \(c\). 对于某一位,如果两颗树上同时有 \(00\) 或者…
题意:给定两个长为n的数组a和b:重新排列a和b,生成数组c,c[i]=a[i] xor b[i]:输出字典序最小的c数组. 分析:将a中的数插入一颗01字典树a中:将b中的数插入一颗01字典树b中:在trie树上查找n次,每次同时在a和b中下移一层:if 能同时走0,则同时走0:else if 能同时走1,则同时走1:else if 树a能走0&&树b能走1,则a走0.b走1:else if 树a能走1&&树b能走0,则a走1.b走0:else 向c中插入一个新数为这两个…