Codeforces C. Classroom Watch
1 second
512 megabytes
standard input
standard output
Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number xwritten in decimal numeral system.
Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.
The first line contains integer n (1 ≤ n ≤ 109).
In the first line print one integer k — number of different values of x satisfying the condition.
In next k lines print these values in ascending order.
21
1
15
20
0
In the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.
In the second test case there are no such x.
从n-n的位数*9到n枚举就行了;
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std; int n,ans[],res,k; int main(){
scanf("%d",&n);
long long g=,gg=;
while(g<=n){
g=g*+;
gg++;
}
gg+=;
for(int i=n-gg*;i<=n;i++){
int x=n-i,a=i;
while(a>){
x=x-a%;
a=a/;
}
if(x==){
res++;
ans[res]=i;
}
}
printf("%d\n",res);
for(int i=;i<=res;i++)
printf("%d\n",ans[i]);
}
Codeforces C. Classroom Watch的更多相关文章
- Codeforces 876C Classroom Watch:枚举
题目链接:http://codeforces.com/contest/876/problem/C 题意: 定义函数:f(x) = x + 十进制下x各位上的数字之和 给你f(x)的值(f(x) < ...
- CodeForces - 876C Classroom Watch (枚举)
题意:已知n,问满足条件"x的各个数字之和+x=n"的x有几个并按升序输出. 分析: 1.n最大1e9,10位数,假设每一位都为9的话,可知x的各个数字之和最大可以贡献90. 2. ...
- codeforces 876 C. Classroom Watch
http://codeforces.com/contest/876/problem/C C. Classroom Watch time limit per test 1 second memory l ...
- Codeforces Round #561 (Div. 2) A. Silent Classroom
链接:https://codeforces.com/contest/1166/problem/A 题意: There are nn students in the first grade of Nlo ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) C. Classroom Watch
http://codeforces.com/contest/876/problem/C 题意: 现在有一个数n,它是由一个数x加上x每一位的数字得到的,现在给出n,要求找出符合条件的每一个x. 思路: ...
- Codeforces 1166A - Silent Classroom
题目链接:http://codeforces.com/problemset/problem/1166/A 思路:统计所有首字母出现的次数,由贪心可知对半分最少. AC代码: #include<i ...
- Codeforces Round #561 (Div. 2) A. Silent Classroom(贪心)
A. Silent Classroom time limit per test1 second memory limit per test256 megabytes inputstandard inp ...
- codeforces Round #441 C Classroom Watch【枚举/注意起点】
C. time limit per test 1 second memory limit per test 512 megabytes input standard input output stan ...
- 「Codeforces Round #441」 Classroom Watch
Discription Eighth-grader Vova is on duty today in the class. After classes, he went into the office ...
随机推荐
- React Native学习(三)—— 使用导航器Navigation跳转页面
本文基于React Native 0.52 参考文档https://reactnavigation.org/docs/navigators/navigation-prop 一.基础 1.三种类型 Ta ...
- Codeforces 915E Physical Education Lessons
原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...
- hackerrank 训练军队
高阶传送魔法 在神奇的Kasukabe国家,人们努力拥有一个技能.一共有N个类型的技能,并且开始的时候拥有第 i 种技能的人有Ci个 . 这个国家有T个巫师,他们有能力将一个人的技能进行转换.每个巫师 ...
- HDU 1005 Number Sequence【多解,暴力打表,鸽巢原理】
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- stl 在 acm中的应用总结
总结一些在acm中常用的小技巧,小函数 之前尝试着总结过很多次.都失败了,因为总是担心不全,理解的也不是很透彻.这次再来一次...其实之前保存了很多的草稿就不发布了,当然,下面说的很不全面,路过的大牛 ...
- Codeforces Round #280 (Div. 2)_C. Vanya and Exams
C. Vanya and Exams time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- UnityShader 表面着色器简单例程集合
0.前言 这些简单的shader程序都是写于2015年的暑假.当时实验室空调坏了,30多个人在实验室中挥汗如雨,闷热中学习shader的日子还历历在目.这些文章闲置在我个人博客中,一年将过,师弟也到了 ...
- 除了四大传统OA软件商,国内还有这些优秀的OA协同产品
国内OA 软件市场经过多年的发展,在产品.应用.服务方面都已相对成熟,也出现了众多优秀的OA软件品牌. 据中国软件协会2017年公布的数据显示:泛微OA.致远OA.华天动力OA.蓝凌OA的销售仍稳居O ...
- 废旧鼠标先别丢,用来学习nRF52832 的QDEC
刚发现nRF52832有一个 QDEC,SDK13.0中还有驱动,但是不太友好. 如果大家有废旧鼠标,建议拆一个编码器下来“学习”.鼠标的一般原理如下: 图一 图中那个SW4 ALPS EC10E ...
- [国嵌攻略][051][NandFlash原理解析]
扮演角色 相当于嵌入式设备的硬盘 NandFlash分类 1.SCL(single level cell):单层式存储 2.MLC(multi level cell):多层式存储 3.SCL在存储格上 ...