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次,那么他就 ... 
随机推荐
- thymeleaf支持java8的日期实例
			一.实体 @Entity public class Customer { @Id @GenericGenerator(name="generator",strategy = &qu ... 
- 莫比乌斯反演题表II
			bzoj3994:[SDOI2015]约数个数和 **很好推+有个小结论bzoj3309:DZY Loves Math ***很好推+线筛某函数/卡常bzoj4816:[Sdoi2017]数字表格 * ... 
- [bzoj1033] [ZJOI2008]杀蚂蚁 Big MoNI
			这个模拟就不用说了吧...... 注意事项(救命的):1.不能回原位 2.在可以打到target的塔打target的时候,其他打不到的继续打自己的(这是显然的事情只是当时已惘然) 3.如果游戏在某一秒 ... 
- 使用setTimeout延时10ms执行onunloadcancel
			在做Web开发时,我们经常用到页面关闭事件onbeforeunload,可以给用户一个选择放弃关闭的机会,就比如这个博客编辑器.如果用户选择了离开,那么onunload事件自然会触发:但若用户选择了取 ... 
- 停止ambari上服务的顺序
			Before performing any upgrades or uninstalling software, stop all of the Hadoop services in the foll ... 
- Android 实现对图片 Exif 的修改(Android 自带的方法)
			很多时候我们都要对我们的图片信息进行一些处理,比如向图片中写入经纬度,拍摄时间,设备信息,作者等等. 这个时候我们就要对我们的图片Exif进行写入信息的操作,当然,我们想知道图片的Exif信息,也可以 ... 
- 【spoj1811 & spoj1812 - LCS1 & LCS2】sam
			spoj1811 给两个长度小于100000的字符串 A 和 B,求出他们的最长公共连续子串. 先将串 A 构造为 SAM ,然后用 B 按如下规则去跑自动机.用一个变量 lcs 记录当前的最长公共 ... 
- mhn 实际部署记录
			新增蜜罐时需要注意,server/collector_v2.py中的DEFAULT_CHANNELS,没有注册这个事件是接收不到新蜜罐的消息的 
- 分享三个USB抓包软件---Bus Hound,USBlyzer 和-USBTrace【转】
			转自:http://bbs.armfly.com/read.php?tid=15377 Bus Hound官方下载地址:http://perisoft.net/bushound/ Bus Hound ... 
- 程序异常退出 却没有产生core文件
			程序异常退出 却没有产生core文件 http://www.cnblogs.com/my_life/articles/4107333.html 
