~~~~
It turns out that the time-out is when the map-based violence is used. I used to use hash. The first time I wrote hash, it was really a fun thing.
Question link: http://poj.org/problem? Id = 1200
Note: 1. The question text is composed of characters, so the ascll code is used as the subscript.
2. the hash array must be larger, otherwise re.
# Include <iostream> # include <cstdio> # include <algorithm> # include <cstring> # include <cmath> # define n 16000000 using namespace STD; int Q [200]; int hash [N]; char STR [N]; int main () {int n, m; while (~ Scanf ("% d", & N, & M) {int val =-1, TOT = 0; scanf ("% s", STR ); int Len = strlen (STR); memset (Q, 0, sizeof (q); memset (hash, 0, sizeof (hash )); // assign values to each character using the ascll code as the subscript. For (INT I = 0; I <Len; I ++) if (! Q [STR [I]) Q [STR [I] = ++ val; // each string with a length of N is given. For (INT I = 0; I <= len-N; I ++) {int S = 0; For (Int J = I; j <I + N; j ++) S + = S * m + Q [STR [J]; // map the hash function. If (! Hash [s]) // as to why do we use a hexadecimal-like ing function, please instruct seller Meng. {Tot ++; hash [s] = 1 ;}} printf ("% d \ n", TOT) ;}return 0 ;}