A research laboratory of a world-leading automobile company has received an order to create a special transmission mechanism, which allows for incredibly efficient kickdown — an operation of switching to lower gear. After several months of research engineers found that the most efficient solution requires special gears with teeth and cavities placed non-uniformly. They calculated the optimal flanks of the gears. Now they want to perform some experiments to prove their findings.

The first phase of the experiment is done with planar toothed sections, not round-shaped gears. A section of length n consists of n units. The unit is either a cavity of height h or a tooth of height 2h. Two sections are required for the experiment: one to emulate master gear (with teeth at the bottom) and one for the driven gear (with teeth at the top).

There is a long stripe of width 3h in the laboratory and its length is enough for cutting two engaged sections together. The sections are irregular but they may still be put together if shifted along each other.

The stripe is made of an expensive alloy, so the engineers want to use as little of it as possible. You need to find the minimal length of the stripe which is enough for cutting both sections simultaneously.

Input

The input file contains several test cases, each of them as described below.

There are two lines in the input, each contains a string to describe a section. The first line describes master section (teeth at the bottom) and the second line describes driven section (teeth at the top). Each character in a string represents one section unit — 1 for a cavity and 2 for a tooth. The sections can not be flipped or rotated.

Each string is non-empty and its length does not exceed 100.

Output

For each test case, write to the output a line containing a single integer number — the minimal length of the stripe required to cut off given sections.

Sample Input

2112112112
2212112
12121212
21212121
2211221122
21212

Sample Output

10
8
15

HINT

相当于两个滑块,一个不懂一个动,求最小长度。下面的代码可以更简洁一点,就是把重复的地方封装成函数,可以省不少代码量。

Accepted

#include<stdio.h>
#include<stdlib.h>
#include<string.h> int main()
{
char a[101];
char b[101];
char c[201];
while (scanf("%s%s", a, b) != EOF)
{
int lena = strlen(a);
int lenb = strlen(b);
int min = lena+lenb; for (int i = 0;i <= lena; i++)
{
int flag = 0;
memset(c, '\0', sizeof(c));
strcpy(c, a);
for (int j = 0;j < lenb;j++)
{
if (c[j + lena - i] != '\0')
{
c[j + lena - i] += b[j] - '0';
if (c[j + lena - i] > '3')
{
flag = 1;break;
}
}
else c[j + lena - i] = b[j];
}
if (!flag)min = strlen(c) < min ? strlen(c) : min;
}
for (int i = 0;i <= lenb;i++)
{
int flag = 0;
memset(c, '\0', sizeof(c));
strcpy(c, b);
for (int j = 0;j < lena;j++)
{
if (c[j + lenb - i] != '\0')
{
c[j + lenb - i] += a[j] - '0';
if (c[j + lenb - i] > '3')
{
flag = 1;break;
}
}
else c[j + lenb - i] = a[j];
}
if (!flag)min = strlen(c) < min ? strlen(c) : min;
}
printf("%d\n",min);
}
}

Kickdown UVA - 1588的更多相关文章

  1. 【每日一题】 UVA - 1588 Kickdown

    题意:uva的题,每道都是有背景的orz,都是阅读理解 题解:暴力模拟,拿着短的那个串,对着长的一格一格往左滑,每滑一格暴力扫一遍.然后再从头往右滑,我这里wa了三发,wa了后习惯性瞎改,改到后来循环 ...

  2. Uva 1588 Kickdown

    这道题思路并不难想,在做题过程中主要遇到的困难有: 因为没有仔细的考虑边界情况,没有分析全面,导致因=没有取到而得不出正确结果,浪费的大量时间. 今后在做这类题目时,一定要先进行一个比较全面的分析+模 ...

  3. 【习题 3-11 UVA - 1588】Kickdown

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟一下就好 一位一位地往右移动. [代码] #include <bits/stdc++.h> using namesp ...

  4. UVa 1588 换抵挡装置

    前言 题目 大意是说,两个槽能够插在一起,并保证每一列的高度不高于3,保证最短长度. 思路 思路很简单,取短字符串遍历长字符串的每一个位置,纪录下位置,并取最短即可. 实现 //习题3-11 换抵挡装 ...

  5. uva 1354 Mobile Computing ——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5

  6. UVA 10564 Paths through the Hourglass[DP 打印]

    UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...

  7. UVA 11404 Palindromic Subsequence[DP LCS 打印]

    UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...

  8. UVA&&POJ离散概率与数学期望入门练习[4]

    POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...

  9. UVA计数方法练习[3]

    UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...

随机推荐

  1. 页面强制重新加载js的办法

    1:线上强制重新加载js的办法 js后缀?v1.0 2:开发环境强制重新加载js的办法?now=Date.now() 3:开发环境强制重新加载js的办法F12进入调试页面选择network下单 dis ...

  2. sql语句的练习,已练习的会以绿色标注!!!

    表架构 Student(S#,Sname,Sage,Ssex) 学生表 Course(C#,Cname,T#) 课程表 SC(S#,C#,score) 成绩表 Teacher(T#,Tname) 教师 ...

  3. 自关联映射:一个表自己关联自己,此时从同一个表中查询,通过起别名将一张表变成两张表,使用join语句。

    实例1:id自关联. 隐式内连接: 实例二:编写一个 SQL 查询,来查找与之前(昨天的)日期相比温度更高的所有日期的 id .返回结果 不要求顺序 . 查询结果格式如下例: Weather +--- ...

  4. PacketStream 和 honeygain 推荐一款可以通过分享带宽赚钱的APP

    方法很简单,只需打开网址 PacketStream 或 honeygain 注册,下载客户端登录即可分享带宽.价格0.1美元/G. 绑定paypal账号即可提现.退出客户端即可停止分享带宽.

  5. 剑指 Offer 12. 矩阵中的路径 + 递归 + 深搜 + 字符串问题

    剑指 Offer 12. 矩阵中的路径 题目链接 题目类似于迷宫的搜索. 需要注意的是,需要首先判断起始搜索的位置,可能有多个起点,都需要一一尝试. 每轮迭代的时候记得将是否遍历标记数组还原为未遍历的 ...

  6. Hi3559AV100外接UVC/MJPEG相机实时采图设计(四):VDEC_Send_Stream线程分析

    下面随笔将对Hi3559AV100外接UVC/MJPEG相机实现实时采图设计的关键点-VDEC_Send_Stream线程进行分析,一两个星期前我写了有三篇系列随笔,已经实现了项目功能,大家可以参考下 ...

  7. CSV 注入实战

    oxo1 前言 之前看到过 CSV 注入的文章,具体想了解的请搜索学习,这里不多作介绍.今天刚好碰到了导出功能,就随手测试一波,没想到还真的存在 CSV 注入漏洞. oxo2 经过 1.测试漏洞 看到 ...

  8. FreeBSD 12.2 阿里云镜像使用说明

    目前直接从阿里云 12.1 升级 12.2 会导致错误.镜像非本人制作.FreeBSD 12.2 阿里云镜像使用说明镜像下载地址: http://t.cn/A6taB5jO修改内容:对 /usr/sr ...

  9. WPF 实战 - 翻页控件

    1. 先上效果 <StackPanel Orientation="Horizontal" HorizontalAlignment="Center"> ...

  10. JVM笔记 -- JVM经历了什么?

    Sun Classic VM 世界上第一款商用 Java 虚拟机,JDK1.4 已经淘汰. 内部只有解释器,可以自己外挂JIT编译器,但是二者只能使用其一,不能配合工作. hotspot 内置了该虚拟 ...