codeforces Round #441 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,求x满足x + x各位数和=n,有多组输出方案数和方案。
【分析】:暴力枚举数位和。注意因为最大就是999999999=81 ,更小的数一定凑不到n, so枚举起点是max(n-81,1)
【代码】:
#include <bits/stdc++.h>
using namespace std;
int save[];
int putu(int n,int i)
{
int p=i;
while(p)
{
i+=p%;
p/=;
}
return i==n;
}
int main(void)
{
int n,ans=;
scanf("%d",&n);
for(int i=max(n-,);i<=n;i++)
{
if(putu(n,i))
{
save[ans++]=i;
}
}
printf("%d\n",ans );
if(ans>)
{
for(int i=;i<ans;i++)
printf("%d\n",save[i] );
}
return ;
}
codeforces Round #441 C Classroom Watch【枚举/注意起点】的更多相关文章
- 「Codeforces Round #441」 Classroom Watch
Discription Eighth-grader Vova is on duty today in the class. After classes, he went into the office ...
- Codeforces Round #441 (Div. 2)【A、B、C、D】
Codeforces Round #441 (Div. 2) codeforces 876 A. Trip For Meal(水题) 题意:R.O.E三点互连,给出任意两点间距离,你在R点,每次只能去 ...
- Codeforces Round #441 (Div. 2)
Codeforces Round #441 (Div. 2) A. Trip For Meal 题目描述:给出\(3\)个点,以及任意两个点之间的距离,求从\(1\)个点出发,再走\(n-1\)个点的 ...
- [日常] Codeforces Round #441 Div.2 实况
上次打了一发 Round #440 Div.2 结果被垃圾交互器卡掉 $200$ Rating后心情复杂... 然后立了个 Round #441 要翻上蓝的flag QAQ 晚饭回来就开始搞事情, 大 ...
- 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 Round #441 (Div. 2, by Moscow Team Olympiad)
A. Trip For Meal 题目链接:http://codeforces.com/contest/876/problem/A 题目意思:现在三个点1,2,3,1-2的路程是a,1-3的路程是b, ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) D. Sorting the Coins
http://codeforces.com/contest/876/problem/D 题意: 最开始有一串全部由"O"组成的字符串,现在给出n个数字,指的是每次把位置n上的&qu ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) B. Divisiblity of Differences
http://codeforces.com/contest/876/problem/B 题意: 给出n个数,要求从里面选出k个数使得这k个数中任意两个的差能够被m整除,若不能则输出no. 思路: 差能 ...
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) A. Trip For Meal
http://codeforces.com/contest/876/problem/A 题意: 一个人一天要吃n次蜂蜜,他有3个朋友,他第一次总是在一个固定的朋友家吃蜂蜜,如果说没有吃到n次,那么他就 ...
随机推荐
- 对Web作用域变量进行迭代
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%@ pa ...
- post 中文乱码处理 接受的编码--->解码成字节数组(无任何编码形式)----->编码成想要的格式
- oracle视图就是封装了一条写好的sql语句 可通过视图修改表结构 ; oracle需要手动创建序列
create sequence student_sid; --创建序列 oracle只能通过手动方式创建序列
- Param指南
param name标签是在这个播放插件中嵌入的一些功能和播放参数: <param name="playcount" value="1"><! ...
- vThunder 安装
vThunder 安装 安装镜像下载地址 https://glm.a10networks.com/downloads A10 全球授权许可管理 https://glm.a10networks.com ...
- Codeforces 821E Okabe and El Psy Kongroo(矩阵快速幂)
E. Okabe and El Psy Kongroo time limit per test 2 seconds memory limit per test 256 megabytes input ...
- EOS docker开发环境
EOS Wiki提供了有关如何使用docker容器编译最新版本代码的说明.但可能有它自己的一些问题,因此我们鼓励你在学习时引用下面镜像.这样最初会更容易,更快. 如果你还没有安装docker,请在此处 ...
- 2017年研究生数学建模D题(前景目标检测)相关论文与实验结果
一直都想参加下数学建模,通过几个月培训学到一些好的数学思想和方法,今年终于有时间有机会有队友一起参加了研究生数模,but,为啥今年说不培训直接参加国赛,泪目~_~~,然后比赛前也基本没看,直接硬刚.比 ...
- tomcat内存配置(二)
Tomcat本身不能直接在计算机上运行,需要依赖于硬件基础之上的操作系统和一个Java虚拟机.Tomcat的内存溢出本质就是JVM内存溢出,所以在本文开始时,应该先对JavaJVM有关内存方面的知识进 ...
- powershell for rename server name
Rename server name if server has not yet joined AD $Hostname = "newname" $username = " ...