time limit per test: 1 second
发布时间:2025-06-24 19:44:21 作者:北方职教升学中心 阅读量:511
There are multiple test cases. The first line of the input contains an integer T (1≤T≤。
99 7。
1758041005111510。
time limit per test: 1 second。,
为从0到。
。
81。
5。有。。
uuku is learning digital dynamic programming.。。
For each test case:。), indicating the number of test cases.。
Input。
Now, he hopes you can help him find out where the number n ranks among the natural numbers that have not disappeared in this situation.。
Example。答案即为。
The first line contains two positive integers n and x (0≤n≤。
12345678 9。
998244353114514 7。只需计数0到n中含x的数量,计算方便我们将n分成多个首位为1,
This made him very panicked because it had a significant impact on the number of statistics.。
【思维分析】。
6053445。
#include <iostream>#include <vector>#include <unordered_map>#include <map>#include <cmath>#include <algorithm>#include <climits>#include <stack>#include <cstring>#include <iomanip>#define i64 long longusing namespace std;i64 n, x;i64 cal(i64 num) { if (num==0) return 0; i64 res = 0, pows = 10, ss = 0; string nums = to_string(num); i64 tmp = num / (nums[0] - '0'); while (pows != tmp * 10) { if (res == 0) { res = 1; ss = pows - res; pows *= 10; continue; } res = res * 10 + ss; ss = pows - res; pows *= 10; } if (nums[0] - '0' > x) res = res * (nums[0] - '0' - 1) + pows / 10; else res *= nums[0] - '0'; return res;}void solve() { i64 res = 0; cin >> n >> x; if (n == 0) { cout << 1 << endl; return; } i64 tmp = pow(10, to_string(n).size() - 1), cnt = 0; string ns = to_string(n); while (tmp != 0) { res += cal(tmp * (ns[cnt++] - '0')); tmp /= 10; } cout << n - res + 1 << endl;}int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; cin >> t; while (t--) { solve(); } return 0;}。Output。
Note。
input。
205404686678741。因为我们拆分n#xff0c;
第一个不一定是1,需要特殊判断,
调整后得。
But one day, he found that the x in the nine digits of 1,2,…,9 had disappeared, which means that all numbers containing the digit x had disappeared.。
It's guaranteed that n doesn't include x.。
9475632111234123 8。
9。
, 1≤x≤9).。
output。
G. Disappearing Number。
计数中含x的数量。
For each test case, output a number indicating the ranking of n.。
分治+类二分+数学。
memory limit per test: 256 megabytes。
For the first example, the natural sequence becomes 0,1,2,3,5,6,7,8,9,2,3,5,6,7,8,9, where the number 9 is the 9 th.。其余为0的整数。注意以下规则:我们设。
9 4。