HDU3065 病毒侵襲持續中

2022-05-09 13:51:10 字數 1666 閱讀 2211

嘟嘟嘟

首先這就是一道ac自動機板兒題。

可能有重複的模板串情況,所以我每乙個節點開乙個vector,記錄是第幾個模板串的結尾。

對於主串,如果不是大寫字母,就都預設是第26條出邊('a' ~ 'z' : 0 ~ 25)。

最後也是最重要的:題面不告訴你有多組資料。

1 #include2 #include3 #include4 #include5 #include6 #include7 #include8 #include9 #include10 #include11

using

namespace

std;

12#define enter puts("")

13#define space putchar(' ')

14#define mem(a, x) memset(a, x, sizeof(a))

15#define rg register

16 typedef long

long

ll;17 typedef double

db;18

const

int inf = 0x3f3f3f3f;19

const db eps = 1e-8;20

const

int maxn = 1e3 + 5;21

const

int max_len = 2e6 + 5;22

inline ll read()

2327

while(isdigit(ch))

28if(last == '

-') ans = -ans;

29return

ans;30}

31 inline void

write(ll x)

3237

38int

n;39

char s[max_len], ss[maxn][55

];40

intans[maxn];

4142

int ch[maxn * 50][27], f[maxn * 50], cnt = 0

;43 vector val[maxn * 50

];44

45void

init()

4651

void insert(int id, char *s)

5263 now =ch[now][c];64}

65val[now].push_back(id);66}

67void

build()

6879}80

}81int getnum(char

c)82

86void query(char *s)

8796}97

98int

main()

99108

build();

109 scanf("%s"

, s);

110query(s);

111for(int i = 1; i <= n; ++i) if(ans[i]) printf("

%s: %d\n

", ss[i], ans[i]);

112}

113return0;

114 }

view code

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...