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 ...
随机推荐
- RabbitMQ入门HelloWorld(C#)(翻译)
介绍 先决条件 本教程假定RabbitMQ已安装并在标准端口(5672)上的本地主机上运行.如果您使用不同的主机,端口或凭据,连接设置将需要调整. 在哪里得到帮助 如果您在阅读本教程时遇到困难,可以 ...
- 有关java里,nextLine()无法输入的问题
在课后习题中用到了以下代码 public static void main(String[] args) { System.out.print("输入学生人数:"); int st ...
- 读了前半本<Thinking in Java>
读了1-14章.这本书真的不适合初学者,可能比较适合有一两年Java经验的人来读.学习真的是一个螺旋递进的过程.刚开始学Java基本语法,书上看到的很多东西觉得过于细枝末节,没见过,用不上,导致书看不 ...
- HDU 2438 Turn the corner(三分查找)
托一个学弟的福,学了一下他的最简便三分写法,然后找了一道三分的题验证了下,AC了一题,写法确实方便,还是我太弱了,漫漫AC路!各路大神,以后你们有啥好的简便写法可以在博客下方留个言或私信我,谢谢了! ...
- JFinal极速开发框架使用笔记(二) 两个问题,一个发现
最近给新人出了一个小测试,我也用JFinal框架做了一下,记录一下使用过程中遇到的坑和新学到的知识点 首先是遇到的两个小问题, 一个是用最新版的eclipse运行JFinal的maven项目报错,经过 ...
- 【程序员的吃鸡大法】利用OCR文字识别+百度算法搜索,玩转冲顶大会、百万英雄、芝士超人等答题赢奖金游戏
[先上一张效果图]: 一.原理: 其实原理很简单: 1.手机投屏到电脑: 2.截取投屏画面的题目部分,进行识别,得到题目和三个答案: 3.将答案按照一定的算法,进行搜索,得出推荐答案: 4.添加了一些 ...
- Android按下home键后重新打开app进入主activity的问题
问题阐述: 当我们写一款App的时候,势必会有这种情况:用户已经进行了多级的操作,现返回栈中已存在多个activity,那么这个时候我们想回到最初的activity难道要一层层的返回吗,对用户来说 无 ...
- zookeeper命令行操作
创建 #[-s] 顺序 #[-e] 临时节点 #path 节点 #data 该节点存储的数据 #acl 证书 create [-s] [-e] path data acl -s或-e指定节点特性:顺序 ...
- 数据库 MySQL基础知识
(关于MySQL的安装,具体见下面博客:http://www.cnblogs.com/wj-1314/p/7573242.html) 一.什么是数据库 ? 数据库是按照数据结构来组织,存储和管理数据的 ...
- console.log 用法
转自http://www.cnblogs.com/ctriphire/p/4116207.html 大家都有用过各种类型的浏览器,每种浏览器都有自己的特色,本人拙见,在我用过的浏览器当中,我是最喜欢C ...