UVA - 1588 ​​​​​​​Kickdown

Kickdown

 UVA - 1588 

题目传送门

解决方法:上板不动,下板向左移;上板不动,下板向右移。

AC代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
char s1[maxn];
char s2[maxn];
char s3[maxn];
int main() 
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    //freopen("out.txt", "w", stdout);
    while(scanf("%s",s1)!=EOF)
    {
        scanf("%s",s2);
        int len1=strlen(s1);
        int len2=strlen(s2);
        if(len1<len2)
        {
            strcpy(s3,s1);
            strcpy(s1,s2);
            strcpy(s2,s3);
            int t;
            t=len1;
            len1=len2;
            len2=t;
        }
        /*printf("%s\n%s\n",s1,s2);*/
        int k1,k2=0,id1,id2,nape=0;
        bool ju=false;
        for(int i=0;i<len1;i++)
        {
            k1=i;
            id1=s1[k1]-'0';
            id2=s2[k2]-'0';
            while(id1+id2<=3)
            {
                nape++;
                k1++;
                k2++;
                if(k1==len1||k2==len2)
                {
                    ju=true;
                    break;
                }
                id1=s1[k1]-'0';
                id2=s2[k2]-'0';
            }
            if(ju)
                break;
            else
            {
                k2=0;
                nape=0;
            }
        }
        k2=len2-1;
        int nape1=0,ju1=false;
        for(int i=len1-1;i>=0;i--)
        {
            k1=i;
            id1=s1[k1]-'0';
            id2=s2[k2]-'0';
            while(id1+id2<=3)
            {
                nape1++;
                k1--;
                k2--;
                if(k1==-1||k2==-1)
                {
                    ju1=true;
                    break;
                }
                id1=s1[k1]-'0';
                id2=s2[k2]-'0';
            }
            if(ju1)
                break;
            else
            {
                k2=len2-1;
                nape1=0;
            }
        }
        nape=max(nape,nape1);
        printf("%d\n",len1+len2-nape);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值