codeforces 355A Vasya and Digital Root】的更多相关文章

题意就是找出一个长度为k的整数,使得它的root为d,k的可能取值为1-1000. 第一眼看到这个题,无从下手,想到那么长的数,暴力肯定超时.其实不然,题目要求只要输出任何一个满足条件的即可,因为任何数的root都是0-9,所以这样的数还是很多的,算一下枚举次数的期望,大概就是5,不知道算的对不对. //cf 355A //2013-10-15-10.48 #include <stdio.h> #include <string.h> int num[1005]; int k, d;…
题目链接:http://codeforces.com/problemset/problem/355/A 题目意思:找出某个经过最多四次dr(n)操作等于d的k位数.   千万不要想得太复杂,想得越简单越好.由于它允许dr(n)的操作最多只能是四次,那么操作一次肯定是符合条件的.也就是经过一次dr(n)操作就能得出直接结果d的数(有k位). 由于这个数不能有前导0,非常简便的一个方法是,这个k位数是这样的:d000...00(0的个数等于k-1).要特别注意,什么时候应该输出“No solutio…
题目传送门 /* 构造水题:对于0的多个位数的NO,对于位数太大的在后面补0,在9×k的范围内的平均的原则 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; int a[MAXN]; int main(void) //Codeforces Round #…
#include <iostream> using namespace std; int main(){ int k,d; cin >> k >>d; ) { k > ? (cout<<<<endl); } else{ cout<<d; ; i < k; ++ i) cout<<; cout<<endl; } }…
/* * c.cpp * * Created on: 2013-10-7 * Author: wangzhu */ /** * 当时比赛时,想得复杂了,也想偏了, * 1).写出来之后,结果达到了预期的结果,不过和给出的输出不一样,糊涂了 * 2).想法太复杂了 * * 比赛之后,看了别人的,原来如此: *结果不唯一, *当根为0,但位数大于1,则没有结果,因为位数大于1,最后的根必然大于0,故没有结果: *当不为0,则应是根后面跟位数减去一个零,即是结果. */ #include<cstdio…
C. Digital Root 题目连接: http://www.codeforces.com/contest/10/problem/C Description Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equat…
Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equation AB = C is correct. Recently Billy studied the concept of a digital root of a…
关于digital root可以参考维基百科,这里给出基本定义和性质. 一.定义 数字根(Digital Root)就是把一个数的各位数字相加,再将所得数的各位数字相加,直到所得数为一位数字为止.而这个一位数便是原来数字的数字根.适用范围为正整数和零.例如:65536,6+5+5+3+6=25,2+5=7,故数根为7. 二.性质 1. 任何数加减9的数字根还是它本身. 2. 9乘任何数字的数字根都是9. 3. 数字根的三则运算 (1). 两数之和的数字根等于这两个数的数字根的和数字根      …
来源:LeetCode 258  Add Dights Question:Given a non-negative integer  num , repeatedly add all its digits until the result has only one digit. For example: Given  num =  , the process is like:   + =  ,   + =  . Since    has only one digit, return it. Fo…
digital root = n==0 ? 0 : n%9==0 ? 9:n%9;可以简单证明一下n = a0*n^0 + a1*n^1 + ... + ak * n^kn%9 = a0+a1+..+ak然后,数学归纳易知结论是正确的.因此9个状态就够了,表示%9的结果.这里需要特殊处理0, 表示状态为0. /* 4351 */ #include <iostream> #include <sstream> #include <string> #include <m…