1 条题解
-
1
思路
做法:直接模拟,枚举 ,看一下 满不满足情况。
做法:类似前缀和方法预处理,用 表示区间 中有 个 数字的个数。
询问的答案跟用前缀和求区间和的方法一样, 中满足条件的数有 个。
时间复杂度 。
代码
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const ll mod = 998244353; const int N = 1e7 + 10; int pre[N]; bool check(int k) { while (k) { if (k % 10 == 1) { return false; } k /= 10; } return true; } int main() { int T; scanf("%d", &T); for (int i = 0; i <= 1e7 + 10; i++) { if (check(i)) { pre[i]++; } pre[i] += pre[i - 1]; } while (T--) { int l, r; scanf("%d%d", &l, &r); if (!l) { printf("%d\n", pre[r]); } else { printf("%d\n", pre[r] - pre[l - 1]); } } return 0; }
- 1
信息
- ID
- 5
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 8
- 标签
- (无)
- 递交数
- 342
- 已通过
- 40
- 上传者