题目链接 http://codeforces.com/contest/631/problem/D, 大体思路是将头尾去掉, 然后匹配中间, 匹配好后在比较两边, 代码如下:
#includeusing namespace std;typedef pair pcl;vector s, t;int n, m;int next[200000+100];int tpnum; char str[10];void getnext(){ int i=1, j=0; next[1] = 0; while(i =t[j].second&& s[i-t.size()+1].first==t[0].first && s[i-t.size()+1].second>=t[0].second) res++; j = next[j]; } } return res;}int main(){ // freopen("1", "r", stdin); scanf("%d%d", &n, &m); for(int i=0; i =t[0].second) res += s[i].second-t[0].second+1; printf("%I64d\n", res); return 0; } if(t.size() == 2){ for(int i=0; i