[Codeforces] 355A - Vasya and Digital Root
2014-08-06 08:10
645 查看
根据数字根的特性,数字A的数字根 = A%9 (当A为9的倍数的时候,数字根不是0而是9)。
已知题意,K位数字,构造数字根为d,那么我们可以先构造出K-1位的9,最后一位是d。
举个例子:
95的数字根 = 9 + 5 = 14 = 5
也就是说,任何数字+9 的数字根不变。
显然K-1位9的数字根+最后一位数字d 的数字根 = d。就可以通过构造出数字根是1---9的所有情况。
我们再考虑一下无解的情况,当输入2 0,是没解的,因为我们可以推断正数的数字根的范围是[1,9]。
只有0的数字根是0,题目要求不能有前导零,所以当d为0时,K>1无解。
已知题意,K位数字,构造数字根为d,那么我们可以先构造出K-1位的9,最后一位是d。
举个例子:
95的数字根 = 9 + 5 = 14 = 5
也就是说,任何数字+9 的数字根不变。
显然K-1位9的数字根+最后一位数字d 的数字根 = d。就可以通过构造出数字根是1---9的所有情况。
我们再考虑一下无解的情况,当输入2 0,是没解的,因为我们可以推断正数的数字根的范围是[1,9]。
只有0的数字根是0,题目要求不能有前导零,所以当d为0时,K>1无解。
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> #include <algorithm> #include <iostream> #include <set> #include <map> #include <queue> #include <stack> using namespace std; int main() { int k, d, ans; while(~scanf("%d %d", &k, &d)) { if(k > 1 && d == 0) { printf("No solution\n"); continue; } for(int i = 0; i < k - 1; i++) { printf("9"); } printf("%d\n", d); } return 0; }
相关文章推荐
- Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
- Codeforces Round #206 (Div. 1)--Vasya and Digital Root 啊啊啊 啊....感觉我的智商为0........
- Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
- Vasya and Digital Root
- A. Vasya and Digital Root
- 构造水题 Codeforces Round #206 (Div. 2) A. Vasya and Digital Root
- codeforces Vasya and Digital Root
- codeforces 355C - Vasya and Robot
- 数学 之 Codeforces 354A - Vasya and Robot
- codeforces 715A Plus and Square Root
- Codeforces - 493D. Vasya and Chess - 博弈
- Codeforces 10C Digital Root 法冠军
- CodeForces 354A - Vasya and Robot (简单思维)
- Vasya and Chess - CodeForces 493 D 博弈
- Vasya and Chess - CodeForces 493 D 博弈
- CodeForces 493 E.Vasya and Polynomial(数学)
- Plus and Square Root CodeForces - 716C
- codeforces 324# C. Marina and Vasya (贪心)
- CodeForces 493 E.Vasya and Polynomial(数学)
- Codeforces 355C Vasya and Robot【贪心+前缀和】