hdu 1251 统计难题(求前缀出现了多少次)
生活随笔
收集整理的這篇文章主要介紹了
hdu 1251 统计难题(求前缀出现了多少次)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1251
#include <iostream> #include <cstring> #include <cstdio> #define mem(a,b) memset(a,b,sizeof(a)); using namespace std; typedef long long ll; const int maxn = 500005; const ll INF = 0x3f3f3f3f; int tot,n,trie[maxn][26],sum[maxn]; bool vis[maxn],flag; void Insert(char *s,int rt) {int len = strlen(s);for(int i = 0; i < len; i++){int k = s[i] -'a';if(trie[rt][k] == 0) trie[rt][k] = ++tot;sum[trie[rt][k]]++;rt = trie[rt][k];} } int Find(char *s,int rt) {int len = strlen(s);for(int i = 0; i < len; i++){int k = s[i] -'a';rt = trie[rt][k];if(rt == 0) return 0;}return sum[rt]; } int main() {tot = 0;int rt = 0;flag = false;char s[105];while(1){gets(s);if(s[0] == NULL){break;}Insert(s,rt);}while(cin >> s) {cout << Find(s,rt) << endl;}return 0; }?
轉載于:https://www.cnblogs.com/LLLAIH/p/11330433.html
總結
以上是生活随笔為你收集整理的hdu 1251 统计难题(求前缀出现了多少次)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Jquery 日历控件
- 下一篇: Membership学习(三)Membe