統計模式串出現次數。
#include #include #include #include #include #include #include #include using namespace std;
typedef long long ll;
const int maxn = 5e4+10;
int trie[maxn][128]; //字典樹
int cntword[maxn]; //記錄該單詞出現次數
int fail[maxn]; //失敗時的回溯指標
int cnt = 0;
int id[maxn];
int ansid[1001];
struct node no[1001];
void insertwords(char s,int len,int index)
}//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 len) }}
char s[2000100];
int main()
fail[0] = 0;
getfail();
scanf("%s",s);//查詢文字串
query(s,strlen(s));
for(int i=1; i<=n; i++)
} }return 0;}/*
8...cc
aabb%c
oooxxcc%daaaaoen....end3aa
bbcc
ooxxcc%daaaoen....end
*/
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...