Link: http://vjudge.net/problem/viewProblem.action? Id = 47586
Question: to give a string, you can set the former number I ~ J and I ~ The J string is considered as a character, and the question is as follows: how many characters are contained in the entire string.
Train of Thought: String hash. Hash starts from the beginning and then from the end. If the hash value is the same, there are two more characters. Finally, process the intermediate characters.
Code:
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <map>#include <cstdlib>#include <queue>#include <stack>#include <vector>#include <ctype.h>#include <algorithm>#include <string>#include <set>#include <ctime>#define PI acos(-1.0)#define maxn 10005#define INF 0x7fffffff#define eps 1e-8#define seed 31typedef long long LL;typedef unsigned long long ULL;using namespace std;ULL aa[50005];void init(){ aa[0]=1; for(int i=1;i<=50000;i++) aa[i]=aa[i-1]*seed;}int main(){ int T; char ss[50005]; scanf("%d",&T); init(); for(int ii=1;ii<=T;ii++) { ULL head=0,tail=0; scanf("%s",ss); printf("Case #%d: ",ii); //cout<<endl; int l=strlen(ss); int k=l/2; int from=0; int ans=0; for(int i=0;i<k;i++) { //cout<<i<<" "<<l-i-1<<endl; //cout<