POJ 3630】的更多相关文章

题目链接: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=3630 思路分析: 求在字符串中是否存在某个字符串为另一字符串的前缀: 即对于某个字符串而言,其是否为某个字符串的前缀,或存在某个其先前的字符串为其前缀: (1)若该字符串为某个字符串前缀,则存在一条从根节点到该字符串的最后一个字符串的路径; (2)若存在某个字符串为该字符串前缀,则在该字符串的查找路径中存在一条子路径,路径的最后的结点的endOfWord 标记为true,表示存在某个字符串为其前缀: 代码: #include <…
[题目链接] http://poj.org/problem?id=3630 [算法] 字典树 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #includ…
这道题也是一道找前缀的问题,很自然地要用到Trie树,但是如果用动态Trie树(即用指针开辟内存)的话,虽然在HDU上可以过(可能是HDU的数据比较水),但在POJ上会TLE , 所以这道题只能用静态Trie树. 实现过程如下: #include<iostream> #include<cstring> #include<string> #include<cstdio> #include<cmath> #include<algorithm&g…
#include<iostream> #include<cstdio> #include<cstring> #define N 100005 using namespace std; ]; int nodeN; int main() { int t, n, i, j, isPrefix, flag; ]; scanf("%d", &t); while(t--) { scanf("%d", &n); isPrefix…
Phone List Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18202    Accepted Submission(s): 6115 Problem Description Given a list of phone numbers, determine if it is consistent in the sense tha…
Trie的应用题目. 本题有两个难点了: 1 动态建立Trie会超时,须要静态建立数组,然后构造树 2 推断的时候注意两种情况: 1) Tire树有133,然后插入13333556的时候.2)插入顺序倒转过来的时候 改动一下标准Trie数的插入函数就能够了: #include <stdio.h> #include <string.h> const int MAX_NODE = 100001; const int MAX_WORD = 11; const int ARR_SIZE =…
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: Emergency 911 Alice 97 625 999 Bob 91 12 54 26 In this case, it's not p…
Phone List Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23722   Accepted: 7289 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…
Phone List 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: Emergency 911 Alice 97 625 999 Bob 91 12 54 26 In this case,…