题解:P14605 [NWRRC 2025] Faulty Fraction

· · 题解

由于先前证明部分存在笔误,现已修正并重新提交。

题意过于简单,这里不在累赘。

思路

注:\text{len}(a) = a 的长度,例如 \text{len}(133) = 3,\text{len}(21) = 2。

::::info[证明(简化版)] 由于 \text{len}(a \times b) 的结果只有 \text{len}(a) + \text{len}(b) 或 \text{len}(a) + \text{len}(b) - 1 两种情况。除法是乘法的逆运算,所以如果 a \div b = c,那么 \text{len}(c) + \text{len}(b) = \text{len}(a) 或者 \text{len}(c) + \text{len}(b) - 1 = \text{len}(a)。同时题目保证一定有解,所以只需解出方程后,分割字符串即可。 ::::

::::info[证明(全过程)] 根据常识,\text{len}(a \times b) 的结果只会有两种情况(最高位不进位以及进位):\text{len}(a) + \text{len}(b) 或者 \text{len}(a) + \text{len}(b) - 1。

由于 s 是 a 和 b 的连接,所以:

设 $\text{len}(s) = n$,$\text{len}(c) = m$,$\text{len}(b) = k$,则 $\text{len}(a) = n - k$。代入上式得:$n - k \in {k + m, k + m - 1}$。由于 $k$ 为整数,所以可能的 $k$ 一定为 $\left\lfloor \frac{n - m - 1}{2} \right\rfloor$。 :::: ```cpp #include<bits/stdc++.h> using namespace std; string s , idk ; int cut; int lens , leni; signed main(){ cin >> s >> idk; lens = s.length(); leni = idk.length(); //考虑到a*b的位数会是a+b-1 or a+b.... cut = (lens - leni - 1) / 2; cout << s.substr(0 , lens - cut) << ' ' << s.substr(lens - cut); return 0; } ``` ~~水题,但写题解太折磨了。以及防抄袭万岁!~~