題意:
給你n個串,再給你乙個大長串,問你之前的n個串中出現過的串的次數。
解:ac自動機解決,使用vis陣列記錄當前字串出現的次數。每當匹配成功則+1,最後輸出非0的vis就行。
關於ac自動機可看我的部落格:ac自動機講解+模板
**:
#include #include #include #include #include #include using namespace std;
const int maxn = 2e6+5;
const int n = 55;
char s[1005][n],s1[n],str[maxn];
int vis[1005];
struct tries
void init()
void insert(char buf,int id)
end[now]=id ;
}void build()
while(!q.empty())}}
void query(char buf)
}//return res;
}};tries ac;
int main()
ac.build();
scanf("%s",str);
ac.query(str);
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...