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 ...
随机推荐
- Java中final修饰符深入研究
一.开篇 本博客来自:http://www.cnblogs.com/yuananyun/ final修饰符是Java中比较简单常用的修饰符,同时也是一个被"误解"较多的修饰符.对很 ...
- bash 基础
bash是一些基本的命令组成,要想学好bash脚本,基本命令是必须要记住 红色标记为着重点 1执行命令,利用状态返回值来判断 0 : 成功 1-255:失败 2: 测试表达式 [ expressio ...
- 敏捷冲刺DAY8
一. 每日会议 1. 照片 2. 昨日完成工作 第一次阶段测试. 3. 今日完成工作 对前七次敏捷冲刺的工作进行完善. 4. 工作中遇到的困难 浏览器兼容性问题.页面响应性能问题.内存溢出问题-- 二 ...
- 【Linux 命令】- find 命令
find 是日常工具箱中功能更强大.更灵活的命令行工具之一,因此值得花费更多的时间. 最简单的,find 跟上路径寻找一些东西.例如: find / 它将找到(并打印出)系统中的每个文件.而且由于一切 ...
- List、Set、Map典型实现
1:集合 Collection(单列集合) List(有序,可重复) ArrayList 底层数据结构是数组,查询快,增删慢 线程不安全,效率高 Vector 底层数据结构是数组,查询快,增删慢 线程 ...
- ADB抓取日志和日志过滤
建议抓取日志之前先清除缓存的log数据:adb logcat -c 网上有人介绍可以这样写:adb logcat -c && adb logcat 1.使用V.D.I.W.E.F.S优 ...
- 'phantomjs.exe' executable needs to be in PATH. (selenium PhantomJS python)
今天selenium PhantomJS python用了下,发现报错,提示我:'phantomjs.exe' executable needs to be in PATH. from seleniu ...
- web端调百度地图页面
在点击进入地图的入口(下面数据是vue渲染的数据) <a class="navigation" v-if="merchant.longitude && ...
- 【.Net】Net开发
博客里的好多文章都是本人看着比较好,就转过来的,好少自己亲自去写点什么,也很少把自己学的一点心得于大家分享,今天特别想聊一下,关于本人做Net开发时的那段回忆! 一.关于知识的回忆 还记得Handle ...
- UVA11735_Corner the Queens
题目是这样的,游戏规则,每个人轮流将二维空间上的皇后往下,往左或者往斜下45度的方向移动. 谁第一个移动到0,0的位置就获胜. 题目给定你若干个矩形,求矩形中任取一点且该点必胜的概率有概率. 其实是这 ...