注意文字串為可見字元,套用模板時不能單純的減去'a',一種解決方法是把size開到128,不過這樣非常不負責任。。。另一種解決方法是在查詢時找到大寫字母以外的字元就把root設為0,並且continue;注意不能預處理出大寫字母,否則a***xxa會預處理出aa,如果模式串為aa就出錯了(當然預處理也有一種解決方法,不過挺麻煩,不推薦)
#include #include #include #include #include using namespace std;
const int maxl = 2 * 1e6 + 10;
const int maxn = 1e5;
const int size = 26;
char str1[1010][55], str2[maxl];
int n, ans[1010];
struct ac
void insert(char *p, int id)
root = child[root][p[i] - 'a'];
}val[root] = id;
}void getfail()
while (!q.empty())
q.push(u);
int v = fail[root];
while (v && !child[v][i]) v = fail[v];
fail[u] = child[v][i];}}
}void search(char *t)
temp = root = child[root][t[i] - 'a'];
while (temp && val[temp]) }}
}ac;
int main()
getchar(); gets(str2);
ac.search(str2);
for (int i = 1; i <= n; i++) }}
return 0;
}
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...