HDU 3065 病毒侵襲持續中 注意多組輸入

2021-10-23 10:41:47 字數 1501 閱讀 6358

ac自動機模板題,判斷各個串分別出現多少次

#include

#include

#include

using

namespace std;

const

int n =

5e4+5;

const

int m =

2e6+5;

const

int c =

1e4+5;

int trie[n]

[128];

//字典樹

int cntword[n]

;//記錄該單詞出現次數

int fail[n]

;//失敗時的回溯指標

int num[n]

;int flag[c]

;int cnt[c]

;int tot =0;

char s[m]

, ss[c][55

];void

insertwords

(char

*s,int l,

int t)

++cntword[root]

;//當前節點單詞數+1

num[root]

= t;

}void

getfail()

}//fail[now] ->當前節點now的失敗指標指向的地方

tire[now][i] -> 下乙個字母為i+'a'的節點的下標為tire[now][i]

while

(!q.

empty()

)else

//否則就讓當前節點的這個子節點

//指向當前節點fail指標的這個子節點

trie[now]

[i]= trie[fail[now]

][i];}

}}void

query

(char

*s,int l)}}

}void

init()

intmain()

fail[0]

=0;getfail()

;scanf

("%s"

, s)

;query

(s,strlen

(s))

;for

(int i =

1; i < c;

++i)

}memset

(trie,0,

sizeof

(trie));

memset

(cntword,0,

sizeof

(cntword));

memset

(flag,0,

sizeof

(flag));

memset

(cnt,0,

sizeof

(cnt));

tot =0;

}return0;

}

hdu 3065 病毒侵襲持續中

題目大意及思路 ac自動機。include include include include include include include include include include includeusing namespace std define inf 0x3f3f3f3f define ...

HDU 3065 病毒侵襲持續中

這就更簡單了,都不用把out標記成false了 題目中的病毒都是大寫字母這個條件應該怎麼用?include include include include include include include include include include include include include ...

HDU 3065 病毒侵襲持續中

詢問每個模式串在文字傳中出現的次數。文字串中出現的字元不一定都是大寫字母,只需要在匹配的時候,對文字串進行特殊處理,將連續的大寫字母段當成合法的乙個文字串即可。然後 就是簡單的統計了。include include include include include include using name...