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

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>
            欧美国内亚洲| 欧美精品国产精品| 欧美日韩国产在线一区| 亚洲裸体在线观看| 一区二区三区四区蜜桃| 国产精品一区一区三区| 久久久亚洲国产天美传媒修理工 | 亚洲人成精品久久久久| 欧美成人免费网站| 99这里有精品| 午夜在线视频观看日韩17c| 国产一区二区福利| 亚洲国产精品成人综合| 欧美视频中文字幕| 久久久久久久国产| 欧美激情女人20p| 午夜激情综合网| 久久久蜜桃一区二区人| 一本色道久久综合精品竹菊| 亚洲欧美日韩国产成人精品影院 | 国产精品乱人伦中文| 久久久久久欧美| 欧美日韩国产限制| 久久久久青草大香线综合精品| 久久免费国产精品1| 亚洲淫性视频| 欧美高清日韩| 久久久久久久综合色一本| 欧美日韩国产成人在线| 久久亚洲视频| 国产精品一区二区在线观看不卡| 久久婷婷人人澡人人喊人人爽 | 亚洲影视九九影院在线观看| 亚洲第一黄色| 亚洲欧美另类久久久精品2019| 最新亚洲视频| 久久久久99| 久久国产99| 国产精品国产三级国产专播精品人 | 暖暖成人免费视频| 国产精品久久亚洲7777| 亚洲国产裸拍裸体视频在线观看乱了 | 欧美专区在线| 亚洲欧美日韩精品综合在线观看| 牛牛影视久久网| 久久婷婷久久| 国产一区二区精品久久99| 一本色道久久综合狠狠躁的推荐| 亚洲激情在线| 久久亚洲精品一区二区| 久久久久亚洲综合| 国产日韩精品视频一区| 一本大道av伊人久久综合| 99精品视频免费| 欧美精品久久久久久久| 欧美大成色www永久网站婷| 韩日午夜在线资源一区二区| 性高湖久久久久久久久| 欧美在线播放高清精品| 国产精品一区久久久| 亚洲婷婷免费| 欧美一区二区在线免费播放| 国产精品久久久久天堂| 亚洲一区在线视频| 欧美一区二区三区久久精品| 国产乱码精品1区2区3区| 亚洲女同同性videoxma| 久久精品免费播放| 国内外成人免费视频| 久久精品道一区二区三区| 久久免费黄色| 亚洲国产高清在线观看视频| 久久综合久久综合久久| 欧美激情一区在线观看| 日韩一区二区免费高清| 欧美特黄一级| 午夜在线精品偷拍| 美国成人直播| 亚洲乱码精品一二三四区日韩在线 | 性做久久久久久久免费看| 久久久国产精品亚洲一区 | 亚洲国产天堂网精品网站| 欧美成人一二三| av成人激情| 久久九九久精品国产免费直播| 国产综合自拍| 欧美激情视频一区二区三区免费| 日韩小视频在线观看| 欧美在线视频免费| 在线观看日韩av先锋影音电影院| 免费在线看一区| 在线亚洲自拍| 美女精品在线观看| 亚洲午夜成aⅴ人片| 国产一区91| 欧美精品一区二区久久婷婷| 亚洲婷婷国产精品电影人久久| 久久免费视频网站| 一区二区三区欧美| 黄色日韩网站| 欧美日韩一区免费| 久久人人爽人人爽| 一区二区三区欧美视频| 免费成人av在线| 亚洲一区黄色| 亚洲激情偷拍| 狠狠狠色丁香婷婷综合久久五月 | 亚洲视频免费在线观看| 欧美激情va永久在线播放| 午夜免费久久久久| 亚洲精品国产日韩| 狠狠色丁香婷婷综合久久片| 欧美色另类天堂2015| 另类成人小视频在线| 亚洲欧美日韩国产综合| 亚洲精品人人| 欧美顶级大胆免费视频| 久久九九全国免费精品观看| 亚洲一区二区欧美| 亚洲精品乱码久久久久| 激情综合网址| 国产一区二区丝袜高跟鞋图片| 欧美视频四区| 欧美精品一区二区三区在线播放 | 99精品久久久| 亚洲福利视频三区| 免费成人你懂的| 久久免费国产精品| 久久精品视频网| 欧美一区二区三区四区在线| 亚洲一区二区动漫| 宅男精品导航| 一区二区三区四区精品| 99国产精品久久久久久久| 亚洲盗摄视频| 亚洲电影自拍| 亚洲激情不卡| 亚洲三级电影全部在线观看高清| 亚洲高清视频的网址| 在线看一区二区| 亚洲风情在线资源站| 在线国产精品一区| 亚洲黄色毛片| 亚洲免费成人av电影| 99re亚洲国产精品| 亚洲一区二区三区国产| 亚洲一区日韩在线| 亚洲伊人伊色伊影伊综合网| 亚洲网址在线| 午夜国产精品视频| 久久www成人_看片免费不卡| 久久精品国产一区二区三区免费看| 欧美淫片网站| 麻豆freexxxx性91精品| 国产精品vvv| 国产精品久久久久aaaa| 国产精品色网| 韩国女主播一区二区三区| 1024亚洲| av成人免费| 午夜精品视频在线观看一区二区| 亚洲欧美在线磁力| 久久久久久久久岛国免费| 免费在线观看精品| 亚洲精品欧美| 99re6热只有精品免费观看 | 亚洲男人的天堂在线观看| 香蕉成人啪国产精品视频综合网| 久久久精品国产一区二区三区| 免费h精品视频在线播放| 欧美日韩亚洲国产精品| 国产女优一区| 亚洲精品乱码| 久久成人人人人精品欧| 亚洲二区免费| 亚洲欧美日韩成人| 免费观看成人www动漫视频| 欧美性猛交99久久久久99按摩 | 欧美激情一区二区三区四区| 国产精品成人国产乱一区| 激情综合色综合久久| 亚洲视频第一页| 久久这里只有精品视频首页| 亚洲片区在线| 久久精品国产2020观看福利| 欧美日韩的一区二区| 狠狠色综合色区| 亚洲欧美自拍偷拍| 亚洲国产精品999| 欧美亚洲视频在线观看| 欧美日韩国产色综合一二三四| 国产偷国产偷亚洲高清97cao| 亚洲精品网址在线观看| 久久―日本道色综合久久| 亚洲视频999| 欧美精品在线观看| 91久久久亚洲精品| 裸体女人亚洲精品一区| 午夜在线视频观看日韩17c| 欧美天堂在线观看|