• <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>

            hdu2896

            病毒侵襲

            Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
            Total Submission(s): 5030    Accepted Submission(s): 1303


            Problem Description
            當(dāng)太陽的光輝逐漸被月亮遮蔽,世界失去了光明,大地迎來最黑暗的時刻。。。。在這樣的時刻,人們卻異常興奮——我們能在有生之年看到500年一遇的世界奇觀,那是多么幸福的事兒啊~~
            但網(wǎng)路上總有那么些網(wǎng)站,開始借著民眾的好奇心,打著介紹日食的旗號,大肆傳播病毒。小t不幸成為受害者之一。小t如此生氣,他決定要把世界上所有帶病毒的網(wǎng)站都找出來。當(dāng)然,誰都知道這是不可能的。小t卻執(zhí)意要完成這不能的任務(wù),他說:“子子孫孫無窮匱也!”(愚公后繼有人了)。
            萬事開頭難,小t收集了好多病毒的特征碼,又收集了一批詭異網(wǎng)站的源碼,他想知道這些網(wǎng)站中哪些是有病毒的,又是帶了怎樣的病毒呢?順便還想知道他到底收集了多少帶病毒的網(wǎng)站。這時候他卻不知道何從下手了。所以想請大家?guī)蛶兔ΑP又是個急性子哦,所以解決問題越快越好哦~~
             

            Input
            第一行,一個整數(shù)N(1<=N<=500),表示病毒特征碼的個數(shù)。
            接下來N行,每行表示一個病毒特征碼,特征碼字符串長度在20—200之間。
            每個病毒都有一個編號,依此為1—N。
            不同編號的病毒特征碼不會相同。
            在這之后一行,有一個整數(shù)M(1<=M<=1000),表示網(wǎng)站數(shù)。
            接下來M行,每行表示一個網(wǎng)站源碼,源碼字符串長度在7000—10000之間。
            每個網(wǎng)站都有一個編號,依此為1—M。
            以上字符串中字符都是ASCII碼可見字符(不包括回車)。
             

            Output
            依次按如下格式輸出按網(wǎng)站編號從小到大輸出,帶病毒的網(wǎng)站編號和包含病毒編號,每行一個含毒網(wǎng)站信息。
            web 網(wǎng)站編號: 病毒編號 病毒編號 …
            冒號后有一個空格,病毒編號按從小到大排列,兩個病毒編號之間用一個空格隔開,如果一個網(wǎng)站包含病毒,病毒數(shù)不會超過3個。
            最后一行輸出統(tǒng)計信息,如下格式
            total: 帶病毒網(wǎng)站數(shù)
            冒號后有一個空格。
             

            Sample Input
            3 aaa bbb ccc 2 aaabbbccc bbaacc
             

            Sample Output
            web 1: 1 2 3 total: 1
             

            Source
             

            Recommend
            gaojie


            還是多串匹配,不過文章多個了

            在搞完一次之后居然發(fā)現(xiàn)后面的都是0,想起來fd()里面不能改變值
            只好用flag數(shù)組標(biāo)記那個用過,nagemeiyongguo

            code
            #include <cstdio>
            #include 
            <cstdlib>
            #include 
            <cstring>
            #include 
            <cmath>
            #include 
            <ctime>
            #include 
            <cassert>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <fstream>
            #include 
            <map>
            #include 
            <set>
            #include 
            <vector>
            #include 
            <queue>
            #include 
            <algorithm>
            #include 
            <iomanip>
            using namespace std;
            #define maxn 65005
            struct node
            {
                
            int next[100];
                
            int fail,count,id;
                
            void init()
                
            {
                    memset(next,
            -1,sizeof(next));
                    count
            =0;
                    id
            =-1;
                    fail
            =-1;
                }

            }
             s[maxn];
            int q[maxn],head,tail;
            bool flag[505];
            int sind,n,m;
            int ans[504],ll;
            void cas_init()
            {
                s[
            0].init();
                sind
            =1;
            }

            void ins(char str[],int id)
            {
                
            int i,j,len,ind;
                len
            =strlen(str);
                ind
            =0;
                
            for(i=0; i<len; i++)
                
            {
                    j
            =str[i]-32;
                    
            if(s[ind].next[j]==-1)
                    
            {
                        s[sind].init();
                        s[ind].next[j]
            =sind++;
                    }

                    ind
            =s[ind].next[j];
                }

                s[ind].count
            ++;
                s[ind].id
            =id;
            }

            void make_fail()
            {
                
            int u,i,p,son;
                head
            =0;
                tail
            =1;
                q[tail]
            =0;
                
            while(head<tail)
                
            {
                    head
            ++;
                    u
            =q[head];
                    
            for(i=0; i<96; i++)
                    
            {
                        
            if(s[u].next[i]!=-1)
                        
            {
                            p
            =s[u].fail;
                            son
            =s[u].next[i];
                            
            while(p!=-1&&s[p].next[i]==-1) p=s[p].fail;
                            
            if(u==0) s[son].fail=0;
                            
            else s[son].fail=s[p].next[i];
                            
            if(s[s[son].fail].count) s[son].count=1;
                            q[
            ++tail]=son;
                        }

                        
            else
                        
            {
                            p
            =s[u].fail;
                            
            while(p!=-1&&s[p].next[i]==-1)
                                p
            =s[p].fail;
                            
            if(u==0) s[u].next[i]=0;
                            
            else  s[u].next[i]=s[p].next[i];
                        }

                    }

                }

            }

            bool fd(char str[])
            {
                
            int di,i,ind,p;
                
            int len=strlen(str);
                ind
            =0;
                ll
            =0;
                
            for(di=0;di<len;di++)
                
            {
                    i
            =str[di]-32;
                    
            while(ind>0&&s[ind].next[i]==-1) ind=s[ind].fail;
                    
            if(s[ind].next[i]!=-1)
                    
            {
                        ind
            =s[ind].next[i];
                        p
            =ind;
                        
            while(p>0&&s[p].count!=-1)
                        
            {
                            
            if(s[p].count>0&&!flag[s[p].id])
                            
            {
                                ans[ll
            ++]=s[p].id;
                                flag[s[p].id]
            =1;
                            }

                            p
            =s[p].fail;
                        }

                    }

                }

                
            return ll>0;
            }

            void print(int x)
            {
                sort(ans,ans
            +ll);
                printf(
            "web %d:",x);
                
            for(int i=0;i<ll;i++)
                printf(
            " %d",ans[i]);
                printf(
            "\n");
            }

            int main()
            {
                
            char str[10005];
                
            char tmp[210];
                scanf(
            "%d",&n);
                gets(tmp);
                cas_init();
                
            for(int i=1; i<=n; i++)
                
            {
                    gets(tmp);
                    ins(tmp,i);
                }

                make_fail();
                scanf(
            "%d",&m);
                gets(tmp);
                
            int res;
                res
            =0;
                
            for(int i=1;i<=m;i++)
                
            {
                    memset(flag,
            0,sizeof(flag));
                    gets(str);
                    
            //puts(str);
                    if(fd(str))
                    
            {
                        res
            ++;
                        print(i);
                    }

                }

                printf(
            "total: %d\n",res);
                
            return 0;
            }



            posted on 2012-08-01 00:45 jh818012 閱讀(144) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因為 3 的 二進制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄]
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評論內(nèi)容較長,點擊標(biāo)題查看
            • --王私江
            国产成人久久精品区一区二区| 日产精品久久久久久久性色| 久久综合九色综合久99| 狠狠色丁香婷婷久久综合不卡| 青青热久久综合网伊人| 色婷婷狠狠久久综合五月| 亚洲一区精品伊人久久伊人| 精品久久久无码21p发布| 久久精品九九亚洲精品| 久久久久亚洲精品无码网址| 亚洲va中文字幕无码久久| 伊人热人久久中文字幕| 久久精品国产亚洲AV忘忧草18| 国产产无码乱码精品久久鸭 | 热99RE久久精品这里都是精品免费 | 丰满少妇人妻久久久久久| 久久久久久国产a免费观看不卡| 久久精品中文无码资源站| 久久精品二区| www.久久热.com| 色偷偷88888欧美精品久久久| 99久久国产亚洲高清观看2024| 久久SE精品一区二区| 久久伊人精品青青草原高清| 一本久久a久久精品亚洲| 久久久久久极精品久久久| 久久―日本道色综合久久| 色欲综合久久躁天天躁蜜桃| 一本久久综合亚洲鲁鲁五月天亚洲欧美一区二区 | 99热精品久久只有精品| 大伊人青草狠狠久久| 超级97碰碰碰碰久久久久最新| 久久成人18免费网站| 国产免费久久久久久无码| 亚洲国产成人久久精品动漫| 国产精品美女久久久久| 国产精品久久久亚洲| 久久国产热精品波多野结衣AV| 青草国产精品久久久久久| 久久久久99精品成人片试看| 色综合久久久久无码专区|