Test instructions
Two bars with a length of n1,n2 (n1,n2<=100) and a height of 1 or 2 per column are given. They need to be placed in a container with a height of 3.
Ask for the shortest container length that can hold them.
Fix one, and the other moves on it, looking for the minimum length.
Since it is possible to choose which fixed, the minimum value is calculated two times.
For example:
2112112112
2212112
The above fixed, then 10, the following fixed, the minimum required 12.
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <cstdlib>6#include <cmath>7#include <cctype>8#include <vector>9#include <queue>Ten#include <map> One#include <Set> A #defineEPS 10e-6 - - using namespacestd; the -typedefLong Longll; - - Chara[ the],b[ the]; + - intMain () + { A while(~SCANF ("%s%s", b)) at { - intLen1 = strlen (a), Len2 =strlen (b); - intI=0, j=0, ans; - while(I<len1 && j<len2) - { - if(a[i]-'0'+b[j]-'0'<=3) in { -i++; toJ + +; + } - Else the { *i = i-j+1; $j =0;Panax Notoginseng } - } theAns = len1+len2-J; +I=0, j=0; A while(I<len1 && j<len2) the { + if(a[i]-'0'+b[j]-'0'<=3) - { $i++; $J + +; - } - Else the { -j = j-i+1;Wuyii =0; the } - } Wuprintf"%d\n", Min (ans,len2+len1-i)); - } About return 0; $}
View Code
Uva 1588-kickdown