UVA - 1588 Kickdown

来源:互联网 发布:php ci框架 编辑:程序博客网 时间:2024/05/16 07:57

题意:给出两个长度分别为n1,n2且每列高度只为1,或者2的长条,需要将它们放入一个高度为3的容器,问容器的最短长度。

分别以bottom为标准,平移,得出一个长度sum1

再以top为标准,得出一个长度sum2

注意题目并没有说底下的比上面的长,所以要分别讨论。

#include <stdio.h>#include <string.h>#include <algorithm>#include <math.h>const int maxn = 110;const int THREE = 3+'0'+'0';char bot[maxn];char top[maxn];int length(char* bot,char* top){int len = strlen(bot);int len1 = strlen(top);int sum = len + len1;for(int i=0; i<len; i++){char* b = bot+i;char* t = top;while(*b && *t){if(*b+*t<=THREE){b++;t++;}else break;}if(!*b || !*t){if(len-i>len1)sum-=len1;else sum-=(len-i);break;}}return sum;}int main(){while(~scanf("%s%s",bot,top)){int sum1 = length(bot,top);int sum2 = length(top,bot);printf("%d\n",sum1<sum2?sum1:sum2);}    return 0;}


0 0