标签:str utc lin can i++ 需要 put namespace span
因为要删去1个串(读错题),所以就直接二分搞就好了。
需要预处理出2个分别从头到尾,或从尾到头需要多长a串的数组,然后二分删去多长就好了。
1 #include<bits/stdc++.h> 2 #define LL long long 3 #define N 100005 4 #define lowbit(x) x&(-x) 5 using namespace std; 6 inline int ra() 7 { 8 int x=0,f=1; char ch=getchar(); 9 while (ch<‘0‘ || ch>‘9‘) {if (ch==‘-‘) f=-1; ch=getchar();} 10 while (ch>=‘0‘ && ch<=‘9‘) {x=x*10+ch-‘0‘; ch=getchar();} 11 return x*f; 12 } 13 char a[N], b[N]; 14 int fl[N], fr[N]; 15 int la, lb, i, j, mid, l, r, a1, a2; 16 int main() 17 { 18 scanf("%s%s",a+1,b+1); 19 la=strlen(a+1); lb=strlen(b+1); 20 for (i=1,fl[0]=j=0; b[i]; i++) 21 { 22 for (j++; j<=la && a[j]!=b[i]; j++); 23 fl[i]=j; 24 } 25 for (i=lb, fr[lb+1]=j=la+1; b[i]; i--) 26 { 27 for (j--; j>0 && a[j]!=b[i]; j--); 28 fr[i]=j; 29 } 30 for (l=0,r=lb; l<=r;) 31 { 32 mid=(l+r)>>1; 33 for (i=0; i+mid<=lb; i++) 34 if (fl[i]<fr[i+mid+1]) break; 35 if (i+mid<=lb) a1=i,a2=mid+i+1,r=mid-1; 36 else l=mid+1; 37 } 38 for (int i=1; i<=a1; i++) putchar(b[i]); 39 for (int i=a2; i<=lb; i++) putchar(b[i]); 40 if (a2-a1>lb) putchar(‘-‘); 41 return 0; 42 }
标签:str utc lin can i++ 需要 put namespace span
原文地址:http://www.cnblogs.com/ccd2333/p/6364492.html