【习题 3-11 UVA - 1588】Kickdown
【链接】 我是链接,点我呀:)
【题意】
【题解】
模拟一下就好 一位一位地往右移动。【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 300;
int a[N+10];
int b[N+10];
string s1,s2;
int ans;
void can(int l,int r){
for (int i = l,j = 1;i <= r && j <= (int) s1.size();i++,j++){
if (a[i]==0) continue;
if (a[i]!=0){
if (a[i]==2){
if (b[j]!=1) return;
}
}
}
int L = min(l,100);
int R = max(r,l+(int)s1.size()-1);
ans = min(ans,R-L+1);
}
int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
while (cin >> s1){
memset(a,0,sizeof a);
cin >> s2;
if ( (int) s1.size() > (int) s2.size()) swap(s1,s2);
for (int i = 0;i < (int) s2.size();i++){
a[100+i] = s2[i]-'0';
}
ans = 1e8;
for (int i = 1;i <= (int) s1.size();i++) b[i] = s1[i-1]-'0';
for (int i = 100-(int)s1.size();i <= 100+(int) s2.size()-1;i++){
can(i,100+(int) s2.size()-1);
}
printf("%d\n",ans);
}
return 0;
}