Full Text Search
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total Submission (s): 1304 Accepted Submission (s): 416
problem DescriptionWe all often use Google to retrieve information, but the process of retrieving information is very difficult to write; now, please write a simple full-text search program.
The description of the problem is this: given a information flow file, the message is completely composed of numbers, the number of not more than 60,000, but not less than 60, and then given a keyword collection, where the number of keywords is not more than 10,000, each keyword information number not more than 60, but also not less than 5 The first 4 digits of the two different keywords are not the same; because the stream file is too long, it has been divided into multiple lines; Please write a program to retrieve the keywords that have appeared in the file.
InputThe first line is two integers m,n;m represents the number of rows of numeric information, n indicates the number of keywords, followed by the M-line information number, followed by a blank line, followed by the N-line keyword, and each keyword in the form: [Key No. 1] 84336606737854833158.
Outputoutput only one row, if the retrieval of a keyword appears, then output, but not repeat, there are spaces in the form such as: Found key: [Key No. 9] [key No. 5]; If not found, the output shape: No key can be Found!.
Sample Input
20 1064637182992073261343335029591134873186356076363490658381626963794324689259644799193839587774777181164887233252428754341 7420073458038799863383943942530626367011418831418830378814827679789991249141417051280978492595526784382732523080941390128 8489360605127437307701765384119125333085916248723048205484230577149620389593902767194319708947712692729150784242949116042 8566885053632287017546318461921227922708048608523219654599327412034854499247688369996639284781889876500021011340728584382 6588950728649155284642040381621412034311030525211673826615398392584951483398200573382259746978916038978673319211750951759 8870808993759474167781629645422981554393211125190558180976427776820952518017283479346130821470967880066302523288303976510 5715908810763546776082235564817030370189348966582884144606907545230378594426241216970375683344697826146512818837849031077 0144518810438159567647733036073099159346768788307780542503526691711872185060586699672220882332373316019934540754940773329 948050821544112511169610221737386427076709247489217919035158663949436676762790541915664544880091332011868983231199331629190771638894322709719381139120 258155869538381417179544000361739177065479939154438487026200359760114591903421347697[key No. 1] 934134543994403697353070375063[key No. 2] 261985859328131064098820791211[key No. 3] 306654944587896551585198958148[ Key No. 4] 338705582224622197932744664740[key No. 5] 619212279227080486085232196545[key No. 6] 333721611669515948347341113196[key No. 7] 558413268297940936497001402385[key No. 8] 212078302886403292548019629313[ Key No. 9] 877747771811648872332524287543[key No. 10] 488616113330539801137218227609
Sample Output
Found key: [Key No. 9] [key No. 5]
AuthorCai Minglun SourceHangzhou Electric ACM Training Team Training Competition (VI)
Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1277
Topic Analysis: Online seems to be engaged in AC automata, here with Trie Tree, ran 62ms, read into the GetChar record the number of lines, the key string to build a dictionary tree, enumerate the suffix of the stream file to the dictionary tree to find, and then with a hash mark
#include <cstdio> #include <cstring>char t[60005], tmp[10], Key[65];bool hash[60005];struct node{node *next [10]; int id; Node () {memset (Next, NULL, sizeof (next)); id =-1; }};void Insert (node *p, char *s, int id) {for (int i = 0; s[i]! = ' + '; i++) {int idx = s[i]-' 0 '; if (P-next[idx] = = NULL) P--NEXT[IDX] = new node (); p = P-NEXT[IDX]; } P-id = ID;} void Search (node *p, char *s) {for (int i = 0; s[i]! = ' s[i '; i++) {int idx =]-' 0 '; if (p, id! =-1 &&!hash[p ID]) {printf ("[Key No.%d]", p-ID); Hash[p, id] = true; } if (P-next[idx] = = NULL) return; p = P-NEXT[IDX]; }}int Main () {int n, m, cnt1 = 0, Cnt2 = 0; scanf ("%d%d", &m, &n); GetChar (); while (Cnt2 < m) {char ch = getchar (); if (ch = = ' \ n ') CNT2++; else t[cnt1++] = ch; } T[cnt1] = ' + '; Node *root = new node (); Memset (hash, false, sizeof (hash)); for (int i = 1; I <= n; i++) {//tmp reads "[Key", "No.", "1]" these useless strings scanf ("%s%s%s%s", TMP, TMP, TMP, Key); Insert (root, key, i); } printf ("Found key:"); for (int i = 0; T[i]! = ' + '; i++) Search (root, t + i); printf ("\ n");}
HDU 1277 Full-Text Search (trie tree application Good question)