#include <iostream>
#include <algorithm>
#include <vector> using namespace std; const int N = ; /* 001~abc-1, 999 abcxegf
1. num[i] < x, 0
2. num[i] == x, 0~efg
3. num[i] > x, 0~999 */ int get(vector<int> num, int l, int r) {//求前面这些位组成的数字是多少
int res = ;
for (int i = l; i >= r; i -- ) res = res * + num[i];
return res;
} int power10(int x) {//求10的i次方
int res = ;
while (x -- ) res *= ;
return res;
} int count(int n, int x) {//1到n当中,x出现的次数
if (!n) return ;
vector<int> num;//每一位
while (n) {
num.push_back(n % );
n /= ;
}
n = num.size();
int res = ;
for (int i = n - - !x ; i >= ; i -- ) {
//判断是否是在枚举最高位
if (i < n - ) {
// i前面所有这些位数
res += get(num, n - , i + ) * power10(i);
if (!x) res -= power10(i);
}
if (num[i] == x) res += get(num, i - , ) + ;
else if (num[i] > x) res += power10(i);
} return res;
} int main() {
int a, b;
while (cin >> a >> b , a) {
if (a > b) swap(a, b); for (int i = ; i <= ; i ++ )
cout << count(b, i) - count(a - , i) << ' ';
cout << endl;
} return ;
}

AcWing 338. 计数问题的更多相关文章

  1. 一些gcd计数问题

    数论什么的全都忘光了吧QAQ 做了几道简单的题练习一下. bzoj1101: [POI2007]Zap 求有多少对数满足 gcd(x,y)=d, 1<=x<=a, 1<=y<= ...

  2. CF 338 D GCD Table(CRT)

    转载请注明出处,谢谢http://blog.csdn.net/ACM_cxlove?viewmode=contents    by---cxlove 给定一个序列,a[1 ..k],问是否存在(i , ...

  3. 扩展Python模块系列(四)----引用计数问题的处理

    承接上文,发现在使用Python C/C++ API扩展Python模块时,总要在各种各样的地方考虑到引用计数问题,稍不留神可能会导致扩展的模块存在内存泄漏.引用计数问题是C语言扩展Python模块最 ...

  4. 置换群、Burnside引理与等价类计数问题

    置换群.Burnside引理与等价类计数问题 标签: 置换群 Burnside引理 置换 说说我对置换的理解,其实就是把一个排列变成另外一个排列.简单来说就是一一映射.而置换群就是置换的集合. 比如\ ...

  5. 腾讯机试题 AcWing 603 打怪兽

    题目链接:https://www.acwing.com/problem/content/605/ 题目大意: 略 分析: 用dp[i][j]表示用j元钱能在前i只怪兽上所能贿赂到的最大武力值. 有一种 ...

  6. [HEOI2013]SAO ——计数问题

    题目大意: Welcome to SAO ( Strange and Abnormal Online).这是一个 VR MMORPG, 含有 n 个关卡.但是,挑战不同关卡的顺序是一个很大的问题. 有 ...

  7. Codeforces 338 D. GCD Table

    http://codeforces.com/problemset/problem/338/D 题意: 有一张n*m的表格,其中第i行第j列的数为gcd(i,j) 给出k个数 问在这张表格中是否 有某一 ...

  8. cojs 二分图计数问题1-3 题解报告

    OwO 良心的FFT练手题,包含了所有的多项式基本运算呢 其中一部分解法参考了myy的uoj的blog 二分图计数 1: 实际是求所有图的二分图染色方案和 我们不妨枚举这个图中有多少个黑点 在n个点中 ...

  9. LOJ #6089. 小 Y 的背包计数问题

    LOJ #6089. 小 Y 的背包计数问题 神仙题啊orz. 首先把数分成\(<=\sqrt n\)的和\(>\sqrt n\)的两部分. \(>\sqrt n\)的部分因为最多选 ...

随机推荐

  1. Spring IoC Container源码分析(二)-bean初始化流程

    准备 Person实例 @Data public class Person { private String name; private int age; } xml bean配置 <?xml ...

  2. 手写数字识别——基于LeNet-5卷积网络模型

    在<手写数字识别——利用Keras高层API快速搭建并优化网络模型>一文中,我们搭建了全连接层网络,准确率达到0.98,但是这种网络的参数量达到了近24万个.本文将搭建LeNet-5网络, ...

  3. leetcode四道组合总和问题总结(39+40+216+377)

    39题目: 链接:https://leetcode-cn.com/problems/combination-sum/ 给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 ...

  4. 题解【洛谷P3456】[POI2007]GRZ-Ridges and Valleys

    题面 考虑 \(\text{Flood Fill}\). 每次在 \(\text{BFS}\) 扩展的过程中增加几个判断条件,记录山峰和山谷的个数即可. #include <bits/stdc+ ...

  5. 你写的 Python 代码总是不规范?用它!

    今天咱们来说说 代码风格 ! 不同的编程语言 有不同的代码风格 ​ ​ ​ ​ ​ Python 的代码规范 就是人们常说的 PEP8 ​ ​ 在这个网站 https://www.python.org ...

  6. JS首字母进行分类合并加排序

    let array = ['fds', 'ewfg1', 'cvd', 'ew', 'qer', 'jjh', 'rth', 'asd', 'vsd', 'tteh', 'fxv']; let map ...

  7. 栈和队列----将单链表的每K个节点之间逆序

    将单链表的每K个节点之间逆序 给定一个单链表的头节点head,实现一个调整链表的函数,使得每K 个节点之间逆序,如果最后剩下不够K 个节点,则不调整最后几个. 例如: 链表:1—>2—>3 ...

  8. The file is absent or does not have execute permission This file is needed to run this program

    tomcat下载后发现startup.sh文件启动不了 原因: 没有权限 解决方案:chmod 777 *.sh

  9. 数据库SQL练习(一):数据查询

    先创建以下3张基本表 1.学生信息表(Student): 2.课程表(Course): 3.成绩表(Score): 4. 将下列数据输入各个表中 建表SQL: CREATE DATABASE Stud ...

  10. 【C语言】输出半径1到10的圆的面积,当面积值超过100时,停止执行本程序

    #include<stdio.h> #define PI 3.142 int main() { int r; float area; ; r <= ; r++) { area = P ...