hdu 4300 Clairewd’s message
2015-08-20 20:14
381 查看
搞了半天才理解题目的意思,以为是拓展KMP,没想到普通的KMP也可以做,无语
#include<iostream> #include<map> #define maxn 100010 using namespace std; string a,b,c; int nextt[maxn]; map<char,char>mapp; void change() { mapp.clear(); for(int i=0;i<a.size();i++) { mapp[a[i]]='a'+i; } } void get_next() { nextt[0]=-1; int l=0,k=-1; while(l<c.size()) { if(k==-1||c[l]==c[k]) nextt[++l]=++k; else k=nextt[k]; } } int solve() { int j=(b.size()+1)/2,i=0; int flag=j; while(j<b.size()) { if(b[j]==c[i]||i==-1) i++,j++; else i=nextt[i]; } //cout<<c<<"~"<<i<<endl; return i; } int main() { cin.sync_with_stdio(false); int t; cin>>t; while(t--) { cin>>a>>b; change(); c=""; for(int i=0;i<b.size();i++) c+=mapp[b[i]]; get_next(); int flag=solve(); cout<<b<<c.substr(flag,b.size()-2*flag)<<endl; } return 0; }
相关文章推荐
- error: Refusing toundefine while domain managed save image exists
- Light oj 1138 - Trailing Zeroes (III) 【二分查找好题】【 给出N!末尾有连续的Q个0,让你求最小的N】
- HDU 5414 CRB and String (2015 Multi-University Training Contest 10 2015多校联合)
- hdu 5414 CRB and String(2015 Multi-University Training Contest 10)
- 2012 Multi-University Training Contest 5 Problem G The Beautiful Road(HDU4346)
- 2012 Multi-University Training Contest 5 Problem F Permutation(HDU4345)
- hdu 5416 CRB and Tree(2015 Multi-University Training Contest 10)
- [已解决]SSH远程登录失败,提示“Password authentication failed”
- Traits
- ireport detail换行问题
- 虚拟化--061 vsphere webclient sdk - SSL certificate verification failed.
- 科学世界的人文关怀:开源科学与人工智能
- 虚拟化--054 vsphere 报错 Failed to connect to VMware Lookup Service
- UVA 529 Addition Chains
- capturing self strongly in this block is likely to lead to a retain cycle
- UVA - 514 Rails
- Keil调试STM32中解析main开始前的工作
- ACboy needs your help again!--hdu1702
- Train Problem I--hdu1022(栈)
- main中int argc, char **argv 含义