CF1202A You Are Given Two Binary Strings...
题目描述
给你两个二进制字符串$x$和$y$,将$y$左移$k$位,再与$x$相加,得到字符串$s_k$,最后将其反转得到$res_k$。求当$res_k$字典序最小时的$k$。
$PS:s_k = f(x) + f(y) * 2 ^ k$($f(a)$为$a$的十进制形式)
输入格式
第一行为一个整数$T$——数据组数
接下来$2T$行每两行为一组数据,第一行为二进制字符串$x$,第二行为二进制字符串$y$。
字符串的长度均小于$10^5$且只由$1$或$0$构成,$1≤f(x)≤f(y)$
输出格式
共$T$行,每行一个整数$k$,即当$res_k$字典序最小时的$k$。
说明/提示
The first query was described in the legend.
In the second query, it's optimal to choose $ k = 3 $ . The $ 2^3 = 1000_2 $ so $ s_3 = 10001_2 + 110_2 \cdot 1000_2 = 10001 + 110000 = 1000001 $ and $ rev_3 = 1000001 $ . For example, if $ k = 0 $ , then $ s_0 = 10111 $ and $ rev_0 = 11101 $ , but $ rev_3 = 1000001 $ is lexicographically smaller than $ rev_0 = 11101 $ .
In the third query $ s_0 = 10 $ and $ rev_0 = 01 $ . For example, $ s_2 = 101 $ and $ rev_2 = 101 $ . And $ 01 $ is lexicographically smaller than $ 101 $ .
The quote from Wikipedia: "To determine which of two strings of characters comes when arranging in lexicographical order, their first letters are compared. If they differ, then the string whose first letter comes earlier in the alphabet comes before the other string. If the first letters are the same, then the second letters are compared, and so on. If a position is reached where one string has no more letters to compare while the other does, then the first (shorter) string is deemed to come first in alphabetical order."