标签:
根据回文串的左边、右边不相同,对于每个点把左边的翻过来,为了避免重复更新,记录当前更新到的右端点rr
1 #include<algorithm> 2 #include<iostream> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cstdio> 6 #include<string> 7 #include<cmath> 8 #include<ctime> 9 #include<queue> 10 #include<stack> 11 #include<map> 12 #include<set> 13 #define rre(i,r,l) for(int i=(r);i>=(l);i--) 14 #define re(i,l,r) for(int i=(l);i<=(r);i++) 15 #define Clear(a,b) memset(a,b,sizeof(a)) 16 #define inout(x) printf("%d",(x)) 17 #define douin(x) scanf("%lf",&x) 18 #define strin(x) scanf("%s",(x)) 19 #define LLin(x) scanf("%lld",&x) 20 #define op operator 21 #define CSC main 22 typedef unsigned long long ULL; 23 typedef const int cint; 24 typedef long long LL; 25 using namespace std; 26 void inin(int &ret) 27 { 28 ret=0;int f=0;char ch=getchar(); 29 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=1;ch=getchar();} 30 while(ch>=‘0‘&&ch<=‘9‘)ret*=10,ret+=ch-‘0‘,ch=getchar(); 31 ret=f?-ret:ret; 32 } 33 char s[100010]; 34 bool bo[100010][26]; 35 int n,a[100010],b[100010]; 36 void find(int x) 37 { 38 re(i,0,25)if(!bo[x][i]) 39 { 40 s[x]=(char)(‘a‘+i); 41 return ; 42 } 43 } 44 int main() 45 { 46 inin(n); 47 re(i,1,n)inin(a[i]); 48 re(i,1,n-1)inin(b[i]); 49 s[1]=‘a‘;int rr=1; 50 re(i,1,n) 51 { 52 if(s[i]==0)find(i),rr=i; 53 int len=a[i]>>1; 54 int l=i-len-1,r=i+len+1; 55 if(l>0&&r<=n)bo[r][s[l]-‘a‘]=1; 56 while(rr<r-1)rr++,s[rr]=s[2*i-rr]; 57 len=b[i]>>1; 58 l=i-len,r=i+len+1; 59 if(l>0&&r<=n)bo[r][s[l]-‘a‘]=1; 60 while(rr<r-1)rr++,s[rr]=s[2*i-rr+1]; 61 } 62 re(i,1,n)printf("%c",s[i]); 63 return 0; 64 }
标签:
原文地址:http://www.cnblogs.com/HugeGun/p/5260062.html