窩今天果斷翻了sb,main函式中忘記寫ac.bfs()這句話了,然後各種單步除錯感覺怎麼這個fail陣列那麼奇怪呢...很無語...後來不小心發現了果斷ac,基本和上一道題類似,不過就是第幾個字串出現幾次就對應的下標++,最後輸出就好了。
#include#include#include#include#include#include#include#includeusing namespace std;
#define n 2000000
int ans[1234];
char s[1234][52];
char v[3000000];
struct trie
void go()
void init(char *v,int id)
mark[p]=id;
}void bfs()
else}}
}void finde(char *v)
int tep=v[i]-'a';
while(next[p][tep]==-1&&p!=root)
p=fail[p];
p=next[p][tep];
if(p==-1) p=root;
q=p;
while(q!=root)}}
} ac;
int main()
ac.bfs();
scanf("%s",v);
ac.finde(v);
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...