codeforces 876 C. Classroom Watch
http://codeforces.com/contest/876/problem/C
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.
题意:
找出所有的x,满足x+x的每一位=n
因为n<=1e9,所以最大的数位之和为81
从n-81 开始枚举即可
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- int n,tot,ans[];
- bool check(int x)
- {
- int y=x,cnt=x;
- while(y) cnt+=y%,y/=;
- return cnt==n;
- }
- int main()
- {
- scanf("%d",&n);
- for(int i=max(,n-);i<=n;i++)
- if(check(i)) ans[++tot]=i;
- printf("%d\n",tot);
- for(int i=;i<=tot;i++) printf("%d ",ans[i]);
- }
codeforces 876 C. Classroom Watch的更多相关文章
- codeforces 876 D. Sorting the Coins
http://codeforces.com/contest/876/problem/D D. Sorting the Coins time limit per test 1 second memory ...
- codeforces 876 F. High Cry(思维)
题目链接:http://codeforces.com/contest/876/problem/F 题解:一道简单的思维题,知道最多一共有n*(n+1)/2种组合,不用直接找答案直接用总的组合数减去不符 ...
- codeforces 876 D. Sorting the Coins(线段树(不用线段树写也行线段树写比较装逼))
题目链接:http://codeforces.com/contest/876/problem/D 题解:一道简单的类似模拟的题目.其实就是看右边连出来有多少连续不需要换的假设位置为pos只要找pos- ...
- Codeforces 1166A - Silent Classroom
题目链接:http://codeforces.com/problemset/problem/1166/A 思路:统计所有首字母出现的次数,由贪心可知对半分最少. AC代码: #include<i ...
- [Codeforces 876]比赛记录
上场$rating$果然炸飞,但是据说这次只要不$FST$就能翻回来QWQ? T1 $dfs$乱搞? T2 取模乱搞,$STL$ $vector$大法好(%%%$ryf$秒出做法) T3 看了半 ...
- 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, by Moscow Team Olympiad) C. Classroom Watch
http://codeforces.com/contest/876/problem/C 题意: 现在有一个数n,它是由一个数x加上x每一位的数字得到的,现在给出n,要求找出符合条件的每一个x. 思路: ...
- Codeforces 876C Classroom Watch:枚举
题目链接:http://codeforces.com/contest/876/problem/C 题意: 定义函数:f(x) = x + 十进制下x各位上的数字之和 给你f(x)的值(f(x) < ...
- 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 ...
随机推荐
- LeetCode 454. 4Sum II (C++)
题目: Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are su ...
- Thunder--Beta发布--美工+文案
作业:https://edu.cnblogs.com/campus/nenu/SWE2017FALL/homework/1366 内容: 美工:原有功能展示.新增功能展示 程序图标 欢迎页面 我的书架 ...
- 2018软工实践—Alpha冲刺(3)
队名 火箭少男100 组长博客 林燊大哥 作业博客 Alpha 冲鸭鸭鸭! 成员冲刺阶段情况 林燊(组长) 过去两天完成了哪些任务 协调各成员之间的工作 协助后端界面的开发 搭建项目运行的服务器环境 ...
- 团队作业the end
GitHub 王德钊 李镇平 陈启昌 黄益颂 汪倍民 演示动态图:为避免现场演示翻车,各个团队需要给出项目各个功能点运行的git图. 还在肝: 分工协作:团队的成员如何分工协作的?对项目的贡献如何(用 ...
- struts2 不返回result的做法
有时候 比如提交一个弹框的表单 提交成功后我们只是让表单关闭并不进行页面跳转,那么action 里面就returne null, 然后result 也不用配置了 版权声明:本文为博主原创文章,未经博主 ...
- lintcode-414-两个整数相除
414-两个整数相除 将两个整数相除,要求不使用乘法.除法和 mod 运算符. 如果溢出,返回 2147483647 . 样例 给定被除数 = 100 ,除数 = 9,返回 11. 标签 二分法 思路 ...
- MDL详解
以下的虚拟内存可以理解成逻辑内存,因为我觉得只有这样才能讲通下面所有的东西.以下的“未分页”指没有为页进行编码. 以下为MDL结构体(我很郁闷,我在MSDN上没有找到这个结构体) typedef st ...
- IT就业·软件工程之我见
随着计算机技术的飞速发展,让人们深切感受到科技让生活更美好的真正含义. 现如今我们的正常生活,社交都越来越离不开网络和终端,因特网和各种终端设备的组合让我们即使相距千里,也能面对面对话交流:购物,我们 ...
- 对IT行业的看法和对软件工程的理解
现在社会上IT行业的人才需求越来越大,而作为一个学软件工程的大学生,我认为IT行业是一个前景十分强大的发展方向,而且现在的社会越来越信息化,未来的生活中,电脑肯定是不可缺少的,所以我认为IT行业这是一 ...
- JS高级 2
递归:函数自己调用自己 在JavaScript中唯一能产生作用域的东西是 函数!js中只有函数可以创建作用域 词法作用域,也叫做静态作用域 //就是在代码写好的那一刻,变量和函数的作用域就已经确定了, ...