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

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 閱讀(2037) 評論(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久久不卡二区| 国产综合视频在线观看| 亚洲理伦电影| 在线看欧美视频| 午夜影院日韩| 亚洲在线观看视频网站| 美女主播视频一区| 久久精品国产91精品亚洲| 欧美日韩一区成人| 亚洲精品老司机| 亚洲人成7777| 久久久噜噜噜久久中文字免| 亚洲一区精彩视频| 欧美精品午夜| 亚洲国产精品一区二区久| 黄色亚洲免费| 久久爱www.| 久久嫩草精品久久久精品一| 国产精品久在线观看| 一区二区三区欧美| 亚洲自拍偷拍网址| 欧美先锋影音| 亚洲一区二区不卡免费| 亚洲永久免费| 国产精品乱码一区二三区小蝌蚪| 亚洲理论在线| 一区二区三区你懂的| 欧美精品一区二区三区视频| 亚洲国产精品一区制服丝袜| 亚洲东热激情| 老司机精品视频网站| 欧美承认网站| 日韩一级黄色大片| 欧美日韩免费观看一区=区三区 | 亚洲图片激情小说| 欧美深夜福利| 在线视频欧美日韩精品| 亚洲影院污污.| 国产欧美一区二区视频| 欧美一区91| 欧美成人午夜视频| 野花国产精品入口| 国产精品久久久久婷婷| 欧美一区二粉嫩精品国产一线天| 麻豆成人91精品二区三区| 亚洲欧洲精品一区二区| 欧美日韩色综合| 亚洲制服欧美中文字幕中文字幕| 久久精品123| 亚洲国产精品123| 欧美日韩精品免费看| 亚洲网友自拍| 美女国产精品| 一区二区成人精品| 国产日韩精品一区二区三区 | 国产欧美精品日韩区二区麻豆天美 | 久久婷婷国产综合尤物精品| 亚洲第一二三四五区| 欧美精品在线免费观看| 亚洲在线不卡| 欧美激情视频一区二区三区免费| 一本到高清视频免费精品| 国产精一区二区三区| 免费在线观看日韩欧美| 亚洲一二三四区| 欧美国产欧美亚洲国产日韩mv天天看完整| 一区二区高清视频在线观看| 国产一区在线视频| 欧美日韩一区二区三区在线视频| 欧美在线91| 一本色道久久综合一区 | 欧美肥婆在线| 欧美在线观看网址综合| 亚洲精品久久久久久久久| 国产精品亚洲精品| 欧美精品一区二区三| 久久精品视频免费| 亚洲一区二区三区免费视频| 欧美国产欧美亚洲国产日韩mv天天看完整| 性做久久久久久免费观看欧美| 亚洲国产婷婷| 国产综合久久久久影院| 国产精品盗摄久久久| 欧美www视频| 久久精品视频网| 亚洲免费在线| 亚洲视频专区在线| 亚洲人成人一区二区在线观看| 久久综合久久久久88| 亚洲小视频在线| 亚洲日本视频| 亚洲国产另类 国产精品国产免费| 国产精自产拍久久久久久蜜| 欧美午夜精品久久久久久久| 免费欧美在线| 免费成人av资源网| 久久久久久网址| 欧美一区二区三区喷汁尤物| 亚洲午夜精品国产| 亚洲综合视频一区| 亚洲一区二区三区777| 一本色道久久综合狠狠躁篇怎么玩 | 亚洲欧美日本伦理| 亚洲欧美激情诱惑| 午夜精品久久久久99热蜜桃导演| 亚洲视频在线观看一区| 制服丝袜亚洲播放| 亚洲天堂免费观看| 一区二区三区四区在线| 一区二区三区毛片| 亚洲综合三区| 性一交一乱一区二区洋洋av| 午夜精品成人在线视频| 欧美一区二区精品| 久久精品99久久香蕉国产色戒| 久久精品二区| 美日韩精品免费| 欧美久久久久久蜜桃| 欧美婷婷久久| 国产日韩精品一区二区| 国语自产偷拍精品视频偷| 一区二区亚洲精品| 亚洲精品国产品国语在线app| 亚洲精品视频中文字幕| 一区二区三区欧美视频| 新67194成人永久网站| 久久久精品一区二区三区| 久久人91精品久久久久久不卡| 老司机午夜精品视频在线观看| 欧美高清在线一区二区| 99re视频这里只有精品| 亚洲欧美自拍偷拍| 久久三级福利| 欧美日韩精品免费看| 国产欧美日韩一级| 亚洲国产毛片完整版| 一区二区三区你懂的| 久久精品国产久精国产爱| 欧美freesex交免费视频| 99re66热这里只有精品3直播| 亚洲综合另类| 男同欧美伦乱| 国产精品夜夜嗨| 亚洲二区在线观看| 亚洲欧美国产制服动漫| 老牛嫩草一区二区三区日本| 亚洲精品一区二区三区99| 午夜精品久久久久99热蜜桃导演| 毛片一区二区| 国产精品亚洲产品| 亚洲免费高清| 久久婷婷影院| 亚洲网址在线| 欧美va天堂| 国产自产女人91一区在线观看| 日韩网站在线看片你懂的| 久久国产精品久久久久久| 亚洲欧洲一区二区在线播放| 性欧美xxxx视频在线观看| 欧美精品一区二区三区蜜臀| 国产资源精品在线观看| 一区二区不卡在线视频 午夜欧美不卡在| 久久国产精品久久国产精品| 亚洲伦伦在线| 久久青草福利网站| 国产欧美日韩亚洲一区二区三区| 日韩午夜免费视频| 欧美成ee人免费视频| 亚洲欧美久久久久一区二区三区| 欧美精品久久久久久久| 影音国产精品| 久久激五月天综合精品| 一区二区欧美视频| 欧美日韩福利视频| 亚洲看片一区| 欧美jjzz| 久久久久久69| 国产午夜精品一区理论片飘花| 亚洲一区二区三区高清| 亚洲精品国久久99热| 欧美成人xxx| 亚洲高清在线| 欧美成人亚洲成人| 久久国产免费看| 国产亚洲欧美一级| 久久国内精品视频| 性色一区二区| 国产视频久久久久久久| 欧美在线免费观看| 亚洲欧美成人在线| 国产精品亚洲综合一区在线观看| 亚洲先锋成人| 中文日韩在线视频| 国产精品欧美日韩久久| 亚洲欧美一级二级三级| 亚洲女人天堂成人av在线| 国产精品一区在线观看| 欧美一区=区|