hdu3065 病毒侵襲持續中 AC自動機

2022-05-31 08:06:11 字數 1241 閱讀 7498

題意:給定一些只含大寫字母的病毒串,再給乙個文字串,問文字串中每個病毒串各出現了多少次

題解:就是用ac自動機,在每個節點末尾有個id記錄是哪個單詞的末尾,然後如果同時是多個單詞的末尾就用乙個next陣列鏈狀記錄當前id的下乙個值。

多組資料坑死人。坑死人。

1 #include2 #include3 #include4 #include5 #include6

using

namespace

std;78

const

int n=50010,s=2000010,a=26;9

intn,num,cnt[n],nt[n],fir[n],sum[n];

10char ss[n][65

],s[s];

11 queueq;

12struct

nodea[n];

1516

void clear(int

x)17

2122

void trie(char *c,int

id)23

34 x=a[x].son[ind];35}

36if(!a[x].id) a[x].id=id,fir[x]=id;

37else nt[id]=a[x].id,a[x].id=id;38}

3940

void

buildac()

4159

else a[x].son[i]=a[fail].son[i];60}

61}62}

6364

void find(char *c)

6570

int ind=c[i]-'

a'+1

;71 x=a[x].son[ind];

72int p=a[x].id;

73while

(p)7478}

79}8081

intmain()

8298

buildac();

99 scanf("%s"

,s);

100find(s);

101for(int i=1;i<=n;i++)

102if(sum[i]) printf("

%s: %d\n

",ss[i],sum[i]);

103}

104105

return0;

106 }

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