Investigating Div-Sum Property UVA - 11361】的更多相关文章

An integer is divisible by 3 if the sum of its digits is also divisible by 3. For example, 3702 is divisibleby 3 and 12(3+7+0+2) is also divisible by 3. This property also holds for the integer 9.In this problem, we will investigate this property for…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2346 数位DP 代码: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <cmath> #include <…
An integer is divisible by 3 if the sum of its digits is also divisible by 3. For example, 3702 is divisibleby 3 and 12(3+7+0+2) is also divisible by 3. This property also holds for the integer 9.In this problem, we will investigate this property for…
题意: 统计[a, b]中有多少个数字满足:自身是k的倍数,而且各个数字之和也是k的倍数. 分析: 详细分析见<训练之南>吧,=_=|| 书上提出了一个模板的概念,有了模板我们就可以分块计算. 虽然书上定义f(x)表示不超过x的非负整数且满足条件的个数,但为了编码方便,代码中f(x)的含义为0~x-1中满足条件的个数. 这样最终所求为f(b+1) - f(a) #include <bits/stdc++.h> using namespace std; int MOD; ]; ][]…
经典数位dp!而且这好像是数位dp的套路板子……不需要讨论原来我很头疼的一些边界. 改天用这个板子重做一下原来的一些数位dp题目. http://blog.csdn.net/the_useless/article/details/53674906 题目大意: 给定a,b,k三个正整数,统计在[a,b]之间的整数n中,有多少n自身是k的倍数,且n的各个数字(十进制)之和也是k的倍数.(1⩽a⩽b⩽231) 题目分析: 这是一道典型的数位DP题. n非常大,若是直接枚举的话会超时,考虑利用加法原理计…
http://www.geeksforgeeks.org/convert-an-arbitrary-binary-tree-to-a-tree-that-holds-children-sum-property/ #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> using namespace std; struc…
http://www.geeksforgeeks.org/check-for-children-sum-property-in-a-binary-tree/ #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <stack> using namespace std; struct node { int data; struct n…
唯一分解定理是指任何正整数都可以分解为一些素数的幂之积,即任意正整数n=a1^p1*a2^p2*...*ai^pi:其中ai为任意素数,pi为任意整数. 题意是输入整数n,求至少2个整数,使得它们的最小公倍数为n,且这些整数的和最小,输出最小的和.由唯一分解定理可看出当每个ai^pi作为一个单独的整数时最优,只要注意你=1时的答案为2,n的因子只有一种时需要加个1以及n=2^31-1不要溢出即可写出程序.需注意的是应从2开始寻找质因子,因为2是最小的素数,由于习惯从1开始循环则是错误的. 代码如…
对于一个数n 设它有两个不是互质的因子a和b   即lcm(a,b) = n 且gcd为a和b的最大公约数 则n = a/gcd * b: 因为a/gcd 与 b 的最大公约数也是n 且 a/gcd + b < a + b 又因为a/gcd 与 b 互质  所以n的最小的因子和为 所有质因子的和 同理推广到多个质因子 由算术基本定理求出所有的质因子 则 nut = 所有质因子 ^ 个数 的和  自己想一想为什么把... 注意n为1时 #include <iostream> #includ…
题意: 统计[a, b]或[b, a]中0~9这些数字各出现多少次. 分析: 这道题可以和UVa 11361比较来看. 同样是利用这样一个“模板”,进行区间的分块,加速运算. 因为这里没有前导0,所以分块的时候要多分几种情况. 以2345为例,这是一个四位数,首先要计算一下所有的一位数.两位数以及三位数各个数字出现的个数. 对应的模板分别为n,n*,n**,其中n代表非零数字,*代表任意数字. 考虑这样一个长为l的模板****(l个*),这样的数共10l个,而且各个数字都是等频率出现,所以每个数…