HDU 5340 Three Palindromes(Manacher乱搞)
来源:互联网 发布:ios仿新浪微博源码 编辑:程序博客网 时间:2024/04/29 13:33
Problem Description
Can we divided a given string S into three nonempty palindromes?
Input
First line contains a single integer T≤20 which denotes the number of test cases.
For each test case , there is an single line contains a string S which only consist of lowercase English letters.1≤|s|≤20000
For each test case , there is an single line contains a string S which only consist of lowercase English letters.
Output
For each case, output the "Yes" or "No" in a single line.
Sample Input
2abcabaadada
Sample Output
YesNo
分析:Manacher之后乱搞。
#include<cstdio>#include<cstring>#include<algorithm>#include<vector>#include<string>#include<iostream>#include<queue>#include<cmath>#include<map>#include<stack>#include<set>using namespace std;#define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i )#define REP( i , n ) for ( int i = 0 ; i < n ; ++ i )#define CLEAR( a , x ) memset ( a , x , sizeof a )const int INF=0x3f3f3f3f;typedef long long LL;const int maxn=1e5+100;char str[maxn],ma[maxn];int mp[maxn],len,t,p[maxn];vector<int>pre;vector<int>suf;void Manacher(){ int l=0; ma[l++]='$';ma[l++]='#'; for(int i=0;i<len;i++) { ma[l++]=str[i]; ma[l++]='#'; } ma[l]='\0'; len=l-1; int tot=0; int mx=0,id=0,ans=0; for(int i=0;i<l;i++) { mp[i]=mx>i?min(mp[2*id-i],mx-i):1; while(ma[i+mp[i]]==ma[i-mp[i]]) mp[i]++; if(i+mp[i]>mx) { mx=i+mp[i]; id=i; } }}int main(){ scanf("%d",&t); while(t--) { scanf("%s",str); pre.clear();suf.clear(); len=strlen(str); if(len<3) { puts("No"); continue; } Manacher(); for(int i=1;i<=len;i++) { if(mp[i]==i) pre.push_back(i); if(i+mp[i]-1==len) suf.push_back(i); } int flag=0; int presz=pre.size(); int sufsz=suf.size(); for(int i=0;i<presz;i++) { int a=pre[i]; for(int j=sufsz-1;j>=0;j--) { int b=suf[j]; if(a>=b) break; int L=a+mp[a]; int R=b-mp[b]; if(L<=2||R>=len-1) continue; if(L==R&&ma[L]=='#') continue; if(L>R) break; int sz=R-L+1; int mid=(L+R)>>1; if(mp[mid]*2-1>=sz) flag=1; } if(flag) break; } puts(flag?"Yes":"No"); } return 0;}/*2aaddaaa*/
0 0
- HDU 5340 Three Palindromes(Manacher乱搞)
- hdu 5340 Three Palindromes 【Manacher】
- hdu 5340 Three Palindromes(manacher)
- HDU 5340-Three Palindromes(Manacher算法)
- hdu-5340 Three Palindromes(Manacher 算法)
- HDU 5340 Three Palindromes (manacher算法)
- HDU 5340 Three Palindromes 暴力+Manacher
- Hdu 5340 Three Palindromes 最大回文串 Manacher
- HDU 5340 Three Palindromes( 折半枚举+Manacher+记录区间 )
- hdu 5340 Three Palindromes
- hdu 5340 Three Palindromes
- hdu 5340 Three Palindromes
- HDU5340 Three Palindromes <Manacher>
- [HDU 5340] Three Palindromes 最长回文串
- hdu 5340 Three Palindromes(manachar)
- hdu5340 Three Palindromes(manacher算法)
- HDOJ 5340 Three Palindromes
- HDU 5340 Three Palindromes ——BestCoder Round #49
- [bzoj1079][SCOI2008]着色方案
- ios--c DAY_3
- http信息头等
- OC连载四-----Foundation框架——字典、日期、异常
- 用户和用户组的学习
- HDU 5340 Three Palindromes(Manacher乱搞)
- 实例讲解,set,multiset,map,multimap关联容器
- Skewness
- Linux内核驱动模块编译
- -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable a
- UI01_UIView
- ios--c DAY_4
- [周赛] HDU - 4970 Killing Monsters
- UIViewController视图控制器(移动self.view,随机颜色)