青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

coreBugZJ

此 blog 已棄。

Computer Virus on Planet Pandora Description, ACM/ICPC 2010/2011 亞洲,福州區域賽 F, UVA 5103

5103 - Computer Virus on Planet Pandora Description
Asia - Fuzhou - 2010/2011

 

Aliens on planet Pandora also write computer programs like us. Their programs only consist of capital letters (` A' to ` Z') which they learned from the Earth. On planet Pandora, hackers make computer virus, so they also have anti-virus software. Of course they learned virus scanning algorithm from the Earth. Every virus has a pattern string which consists of only capital letters. If a virus's pattern string is a substring of a program, or the pattern string is a substring of the reverse of that program, they can say the program is infected by that virus. Give you a program and a list of virus pattern strings, please write a program to figure out how many viruses the program is infected by.

 

Input 

There are multiple test cases. The first line in the input is an integer T (T$ \le$10) indicating the number of test cases.

For each test case:

The first line is a integer n (0 < n$ \le$250) indicating the number of virus pattern strings.

Then n lines follows, each represents a virus pattern string. Every pattern string stands for a virus. It's guaranteed that those n pattern strings are all different so there are n different viruses. The length of pattern string is no more than 1,000 and a pattern string at least consists of one letter.

The last line of a test case is the program. The program may be described in a compressed format. A compressed program consists of capital letters and ``compressors". A ``compressor" is in the following format:

 


[qx]

 


q is a number (0 < q$ \le$5, 000, 000) and x is a capital letter. It means q consecutive letter x's in the original uncompressed program. For example, [6K] means ` KKKKKK' in the original program. So, if a compressed program is like:

 


AB[2D]E[7K]G

 


it actually is ABDDEKKKKKKKG after decompressed to original format.

The length of the program is at least 1 and at most 5,100,000, no matter in the compressed format or after it is decompressed to original format.

 

Output 

For each test case, print an integer K in a line meaning that the program is infected by K viruses.

 


Hint: In the second case in the sample input, the reverse of the program is ` GHIFEDCCBA', and ` GHI' is a substring of the reverse, so the program is infected by virus ` GHI'.

 

Sample Input 

 

3 
2
AB
DCB
DACB
3
ABC
CDE
GHI
ABCCDEFIHG
4
ABB
ACDEE
BBB
FEEE
A[2B]CD[4E]F

 

Sample Output 

 

0 
3
2

 


Fuzhou 2010-2011


AC 自動機。。。

  1 #include <iostream>
  2 #include <cstdio>
  3 
  4 using namespace std;
  5 
  6 const int ACTC = 26;
  7 const int ACTM = 200000;
  8 const int ACQL = ACTM;
  9 
 10 struct AC
 11 {
 12         int count;
 13         AC *fail;
 14         AC *ch[ ACTC ];
 15 };
 16 
 17 AC *que[ ACQL ];
 18 
 19 AC* ac_new( bool init = false ) {
 20         int i;
 21         AC *p;
 22         static AC memAC[ ACTM ];
 23         static int tot = 0;
 24         if ( init ) {
 25                 tot = 0;
 26                 return 0;
 27         }
 28         p = memAC + tot++;
 29         p->count = 0;
 30         p->fail  = 0;
 31         for ( i = 0; i < ACTC; ++i )
 32                 p->ch[ i ] = 0;
 33         return p;
 34 }
 35 
 36 int ac_add( AC* &root, const char *first, const char *last ) {
 37         AC ** p = &root;
 38         for ( ; ; ) {
 39                 if ( *== 0 ) *= ac_new();
 40                 if ( first == last ) return ++( (*p)->count );
 41                 p = &( (*p)->ch[ *first++ ] );
 42         }
 43 }
 44 
 45 void ac_build( AC *root ) {
 46         // root != 0
 47         int qh = 0, qt = 1, i;
 48         AC *pf, *pc, *pt;
 49         root->fail = 0;
 50         que[ 0 ] = root;
 51         while ( qh != qt ) {
 52                 pf = que[ qh ];
 53                 qh = ( qh + 1  ) % ACQL;
 54                 for ( i = 0; i < ACTC; ++i ) {
 55                         if ( pc = pf->ch[ i ] ) {
 56                                 for ( pt = pf->fail; pt && ( pt->ch[ i ] == 0 ); pt = pt->fail )
 57                                         ;
 58                                 pc->fail = pt ? pt->ch[ i ] : root;
 59                                 que[ qt ] = pc;
 60                                 qt = ( qt + 1 ) % ACQL;
 61                         }
 62                 }
 63         }
 64 }
 65 
 66 int ac_query( AC *root, const char *first, const char *last ) {
 67         // root != 0
 68         int ans = 0;
 69         AC *= root, *q;
 70         while ( first != last ) {
 71                 while ( p && ( p->ch[ *first ] == 0 ) ) {
 72                         p = p->fail;
 73                 }
 74                 if ( p ) {
 75                         q = p = p->ch[ *first++ ];
 76                         while ( q && ( q->count != -1 ) ) {
 77                                 ans += q->count;
 78                                 q->count = -1;
 79                                 q = q->fail;
 80                         }
 81                 }
 82                 else {
 83                         p = root;
 84                         ++first;
 85                 }
 86         }
 87         return ans;
 88 }
 89 
 90 char txt[ 5100009 ], pat[ 1009 ];
 91 AC *root;
 92 
 93 void expand( char *out ) {
 94         char ch;
 95         char *= out;
 96         ch = getchar();
 97         while ( (ch!='\n'&& (ch!=EOF) ) {
 98                 if ( ('A'<=(ch)) && ((ch)<='Z') ) {
 99                         *q++ = ch;
100                 }
101                 else {
102                         ch = getchar();
103                         int num = 0;
104                         while ( ('0'<=(ch)) && ((ch)<='9') ) {
105                                 num = num * 10 + ( ch - '0' );
106                                 ch = getchar();
107                         }
108                         while ( num-- > 0 ) {
109                                 *q++ = ch;
110                         }
111                         ch = getchar();
112                 }
113                 ch = getchar();
114         }
115         *= 0;
116 }
117 
118 int main() {
119         int td, n, ans;
120         char *pc, *ph, *pt;
121         scanf( "%d"&td );
122         while ( td-- ) {
123                 scanf( "%d%*c"&n );
124                 ac_new( true );
125                 root = 0;
126                 while ( n-- ) {
127                         gets( pat );
128                         for ( pc = pat; *pc; ++pc )
129                                 *pc -= 'A';
130                         ac_add( root, pat, pc );
131                 }
132                 ac_build( root );
133                 expand( txt );
134                 for ( pc = txt; *pc; ++pc )
135                         *pc -= 'A';
136                 ans = ac_query( root, txt, pc );
137                 ph = txt;
138                 pt = pc - 1;
139                 while ( ph < pt ) {
140                         char tmp = *ph;
141                         *ph = *pt;
142                         *pt = tmp;
143                         ++ph;
144                         --pt;
145                 }
146                 ans += ac_query( root, txt, pc );
147                 printf( "%d\n", ans );
148         }
149         return 0;
150 }
151 


posted on 2011-03-25 19:27 coreBugZJ 閱讀(2026) 評論(0)  編輯 收藏 引用 所屬分類: ACM

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            久久中文在线| 欧美日韩亚洲成人| 在线欧美日韩精品| 91久久久亚洲精品| 国产精品视频不卡| 欧美ed2k| 性做久久久久久久久| 亚洲综合视频网| 亚洲福利国产| 宅男66日本亚洲欧美视频| 国产亚洲va综合人人澡精品| 欧美成人免费大片| 国产精品国产三级国产aⅴ浪潮| 久久aⅴ乱码一区二区三区| 久久频这里精品99香蕉| 亚洲视频日本| 老鸭窝亚洲一区二区三区| 99视频超级精品| 久久成人一区| 亚洲午夜精品久久久久久app| 欧美一区深夜视频| 一区二区三区欧美视频| 久久福利视频导航| 亚洲一区二区三区精品在线| 久久精品日产第一区二区| 一区二区三区四区五区在线| 久久久久久久欧美精品| 午夜久久影院| 欧美四级在线观看| 欧美激情一区二区三区高清视频| 国产精品久久久久av免费| 女人色偷偷aa久久天堂| 国产精品一区2区| 亚洲美女av网站| 亚洲国产成人在线| 欧美成人按摩| 欧美日本精品一区二区三区| 久久精品91久久久久久再现| 欧美国产日韩精品| 亚洲欧美卡通另类91av| 久久久久久一区二区| 欧美一级淫片播放口| 国产精品国产a级| 欧美制服第一页| 麻豆精品在线观看| 欧美制服丝袜第一页| 国产日韩高清一区二区三区在线| 亚洲美女视频在线观看| 中文国产亚洲喷潮| 欧美理论在线播放| 久久av在线| 欧美日韩精品一区二区天天拍小说 | 久久久久国产一区二区三区四区 | 亚洲大片在线观看| 日韩一区二区免费看| 欧美精品一区二区在线播放| 欧美成人69av| 一区精品在线| 在线午夜精品自拍| 在线免费不卡视频| 久久精品国产v日韩v亚洲| 亚洲国产你懂的| 久久美女艺术照精彩视频福利播放| 在线视频精品一区| 另类酷文…触手系列精品集v1小说| 香蕉成人伊视频在线观看| 久久精品亚洲| 欧美成人中文字幕在线| 亚洲电影中文字幕| 嫩草影视亚洲| 亚洲精品之草原avav久久| 夜夜精品视频| 国产亚洲激情在线| 亚洲欧美综合国产精品一区| 国产一区二区中文| 欧美aa国产视频| 亚洲精品欧美精品| 西西裸体人体做爰大胆久久久| 国产乱码精品一区二区三区av| 午夜在线播放视频欧美| 免费观看日韩| 一区二区高清在线| 欧美国产日韩一二三区| 亚洲婷婷在线| 国产精品久久久久久久久免费 | 一区二区三区日韩在线观看| 欧美三级乱码| 午夜精品久久久久久久久| 麻豆精品视频在线观看| 一区二区三区国产在线观看| 国产欧美亚洲一区| 欧美成在线视频| 亚洲女女做受ⅹxx高潮| 亚洲国产高清视频| 亚洲视频自拍偷拍| 狠狠色丁香久久综合频道| 欧美日韩不卡视频| 性久久久久久久久久久久| 欧美激情视频一区二区三区免费| 亚洲视频网站在线观看| 国产一区二区三区成人欧美日韩在线观看 | 麻豆成人在线播放| 在线一区二区三区四区| 国产亚洲精品福利| 欧美人成在线视频| 久久国产精品毛片| 亚洲一区三区在线观看| 欧美国产日韩在线| 久久国产精品一区二区三区四区| 99re亚洲国产精品| 在线看片欧美| 国产一区二区三区网站 | 亚洲午夜小视频| 国产精品区一区二区三区| 久久福利精品| 一本色道婷婷久久欧美| 亚洲色图制服丝袜| 一本色道久久综合狠狠躁篇的优点| 亚洲春色另类小说| 国外成人网址| 国产精品一区二区三区久久| 欧美无乱码久久久免费午夜一区| 免费观看在线综合色| 久久成人免费日本黄色| 午夜精品免费在线| 亚洲主播在线| 亚洲一区二区三区中文字幕在线| 欧美成人有码| 久久高清一区| 亚洲最黄网站| 亚洲影视在线播放| 午夜精品久久久99热福利| 欧美国产欧美综合 | 曰本成人黄色| 欧美日韩在线播| 欧美一区二区三区视频免费播放 | 欧美高清视频一区二区三区在线观看 | 99国产精品一区| 国产精品sm| 欧美高清在线观看| 欧美一级理论性理论a| 亚洲精品色婷婷福利天堂| 国产精品男gay被猛男狂揉视频| 久久精品亚洲热| 在线视频欧美精品| 欧美激情精品久久久久久变态| 亚洲主播在线观看| 亚洲人成啪啪网站| 国产一区视频观看| 欧美色精品在线视频| 亚洲国产天堂久久综合网| 中日韩高清电影网| 亚洲激情成人在线| 国产手机视频一区二区| 欧美日韩你懂的| 欧美成人有码| 欧美a级一区| 你懂的成人av| 久久久av水蜜桃| 欧美亚洲一区二区三区| 一本不卡影院| 99精品久久久| 亚洲精品免费在线| 亚洲国产精品成人va在线观看| 久久久精品动漫| 亚洲一区二区三区在线看| 欧美大秀在线观看| 久久久久99精品国产片| 久久国产精品久久久久久| 亚洲丰满在线| 国产精品中文在线| 国产精品第一页第二页第三页| 欧美母乳在线| 国产嫩草一区二区三区在线观看| 国产精品入口夜色视频大尺度 | 99精品视频一区二区三区| 一区二区欧美精品| 久久精品2019中文字幕| 亚洲第一成人在线| 亚洲天堂成人| 麻豆国产精品777777在线| 欧美日韩国产在线播放网站| 国产日韩精品一区二区| 亚洲人成小说网站色在线| 欧美一区二区三区精品| 亚洲激情另类| 欧美在线日韩在线| 欧美视频一区在线| 91久久在线观看| 久久久久国内| 亚洲一区二区三区乱码aⅴ蜜桃女| 久久全国免费视频| 国产精品视频免费在线观看| 亚洲精品一区二区网址| 久久成人精品| 在线午夜精品| 欧美日韩日日骚| 亚洲精品影视在线观看| 久久久久国产一区二区三区| 在线亚洲欧美|