Viruses
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 42583 Accepted Submission(s): 9167
Problem Description
When the sun is shining gradually obscured by the moon, the world lost the light, the earth to usher in the darkest moments. . . . At such moments, people are excited - we can see the 500 years of the wonders of the world in their lifetime, that is how happy thing ah ~ ~
but always has those sites on the web, start by curious people heart, name describes eclipse banner, wantonly spread the virus. Small t become one of the unfortunate victims. Small t so angry that he decided to take the world on all sites with the virus have to find out. Of course, everyone knows that this is impossible. T small but insisted it can not complete the task, he said: "The children and grandchildren infinite Kui also!" (Successors of the Foolish Old Man).
Everything is hard in the beginning, small t collect a lot of virus signatures, but also collected a number of strange source site, he wanted to know which of these sites is a virus, but also with what kind of virus? Incidentally, in the end he wanted to know how much the collection site with a virus. This time he did not know what the bite. So I would like to help out. T is a little impatient Oh, so to solve the problem as quickly as possible ohhh
but always has those sites on the web, start by curious people heart, name describes eclipse banner, wantonly spread the virus. Small t become one of the unfortunate victims. Small t so angry that he decided to take the world on all sites with the virus have to find out. Of course, everyone knows that this is impossible. T small but insisted it can not complete the task, he said: "The children and grandchildren infinite Kui also!" (Successors of the Foolish Old Man).
Everything is hard in the beginning, small t collect a lot of virus signatures, but also collected a number of strange source site, he wanted to know which of these sites is a virus, but also with what kind of virus? Incidentally, in the end he wanted to know how much the collection site with a virus. This time he did not know what the bite. So I would like to help out. T is a little impatient Oh, so to solve the problem as quickly as possible ohhh
Input
The first line, an integer N (1 <= N <= 500), represents the number of virus signatures.
Next N rows, each row represents a virus signature, signature string length between 20-200.
Each virus has a number, so to 1-N.
Different numbers of virus signatures will not be the same.
Following this line, there is an integer M (1 <= M <= 1000), represents the number of sites.
Next M rows, each row represents a site source, source string length between 7000-10000.
Every website has a number, and so is 1-M.
In the above character strings are visible ASCII code characters (not including the carriage return).
Next N rows, each row represents a virus signature, signature string length between 20-200.
Each virus has a number, so to 1-N.
Different numbers of virus signatures will not be the same.
Following this line, there is an integer M (1 <= M <= 1000), represents the number of sites.
Next M rows, each row represents a site source, source string length between 7000-10000.
Every website has a number, and so is 1-M.
In the above character strings are visible ASCII code characters (not including the carriage return).
Output
Followed by format output following site by site ID number and contains a virus from small to large output number, with the virus, one per line toxic site information.
No web site: No virus virus numbers ...
there is a space after the colon, the virus numbered in ascending order, between two numbers separated by a space virus, if a site contains a virus, the virus does not number more than three.
The last line of output statistics, in the following format
total: the number of websites with the virus
after the colon there is a space.
No web site: No virus virus numbers ...
there is a space after the colon, the virus numbered in ascending order, between two numbers separated by a space virus, if a site contains a virus, the virus does not number more than three.
The last line of output statistics, in the following format
total: the number of websites with the virus
after the colon there is a space.
Sample Input
3
aaa
bbb
ccc
2
aaabbbccc
bbaacc
Sample Output
web 1: 1 2 3
total: 1
Meaning of the questions: to n words, m a text string, text strings are asking that there have been a few words
There are several text strings appeared word
Note: pit, there are 128 letters, not just to open an array large enough time to find and achievements of the subscript i d irreducible 'a' treatment, or has been runtime_error
#include <the iostream> #include < String .h> #include < String > #include <algorithm> #include <Queue> #include < SET > #define LL Long Long the using namespace STD; int Tree [ 105000 ] [ 128 ], VIS [ 105000 ], Fail [ 105000 ]; // characters may appear in ASCII code, the letter is not int T, n-, CNT, ID, the root, NUM = 0 ; String S, SS; SET < int > m; void INSERT ( int Y) // achievements { the root = 0 ; for ( int I = 0 ; S [I]; I ++ ) { ID = S [I]; // -'a ', where irreducible character a, possible negative direct default to int IF (Tree [the root] [ID] == 0 ) Tree [the root] [ID] = ++ NUM; the root = Tree [the root] [ID]; } VIS [the root] Y =; // words ending flag } void build () // Construction mismatch pointer { Queue< Int > P; for ( int I = 0 ; I < 128 ; I ++ ) { IF (Tree [ 0 ] [I]) // second row all the letters appeared mismatch pointer to the root node 0 { Fail [Tree [ 0 ] [I]] = 0 ; p.push (Tree [ 0 ] [I]); } } the while (! p.empty ()) { the root = p.front (); p.pop () ; for ( int I = 0 ; I < 128; I ++ ) { IF (Tree [the root] [I] == 0 ) // No contribution, the absence of the letter Continue ; p.push (Tree [the root] [I]); int FA = Fail [the root]; / / fa parent node is the while (fa && Tree [fa] [I] == 0 ) // fa is not 0, and the child node is not the letter fa fa = Fail [fa]; // continue to determine the parent node of the sub-fa this node has no letter Fail [Tree [the root] [I]] = Tree [FA] [I]; // find the pointer to construct a mismatch } } } int Search ( String SS) // find { the root= 0 , CNT = 0 ; for ( int I = 0 ; SS [I]; I ++ ) { ID = SS [I]; the while (the root && Tree [the root] [ID] == 0 ) // mismatch transfer the root = Fail [the root]; the root = Tree [the root] [ID]; int TEMP = the root; the while (VIS [TEMP]) { CNT = CNT + . 1 ; m.insert (VIS [TEMP]); // VIS [TEMP] = 0 ; // clear the flag, avoid duplication temp=fail[temp]; } } return cnt; } int main() { int mm; cin>>n; { // memset(tree,0,sizeof(tree)); // memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++) { cin>>s; insert(i); } build(); int ans=0; cin>>mm; for(int i=1;i<=mm;i++) { m.clear(); cin>>ss;//文本串 if(search(ss)!=0) { ans++; cout<<"web "<<i<<": "; set<int>::iterator it; for(it=m.begin();it!=m.end();it++) { if(it==m.begin()) cout<<*it; else cout<<' '<<*it; } cout<<endl; } } cout<<"total: "<<ans<<endl; } }