标签:appears mission ilo bsp tchar represent pre cpp rac
b babd a abcd
0 2 aza No solution!
<span style="font-size:18px;">#include <iostream> #include <cstdio> #include <cstring> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <cmath> #include <algorithm> using namespace std; const double eps = 1e-6; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const int MOD = 1000000007; #define ll long long #define CL(a,b) memset(a,b,sizeof(a)) #define MAXN 200010 char ch,str[MAXN*2],s[MAXN]; int p[MAXN*2]; int pre,maxx; void init() { int i,l; CL(str, '\0');///初始化str str[0] = '$'; str[1] = '#'; for(i=0,l=2; s[i]; i++,l+=2) { str[l] = s[i]; str[l+1] = '#'; } } void solve() { int id; int mx = 0; maxx = 0; for(int i=1; str[i]; i++) { if(mx > i) p[i]=p[2*id-i]>(mx-i)?(mx-i):p[2*id-i]; else p[i] = 1; while(str[i-p[i]] == str[i+p[i]]) p[i]++; if(p[i]+i > mx) { mx = p[i] + i; id = i; } if(maxx < p[i]) {///记录最长回文点的位置 maxx = p[i]; pre = i; // cout<<str<<endl; //printf("maxx=%d pre=%d\n",maxx,pre); } } maxx--; } int main() { while(scanf("%c%s",&ch,s)==2) { getchar(); int x = ch - 'a'; for(int i=0; s[i]; i++) { int t = s[i] - 'a'; s[i] = (t - x + 26)%26 + 'a'; } init(); solve(); int r = pre/2 + maxx/2 - 1; int l = r - maxx + 1; if(maxx > 1) { printf("%d %d\n",l,r); for(int i=l; i<=r; i++) printf("%c",s[i]); printf("\n"); } else printf("No solution!\n"); } return 0; } </span>
标签:appears mission ilo bsp tchar represent pre cpp rac
原文地址:http://www.cnblogs.com/jzdwajue/p/7182490.html