题意:已知n,问满足条件"x的各个数字之和+x=n"的x有几个并按升序输出。

分析:

1、n最大1e9,10位数,假设每一位都为9的话,可知x的各个数字之和最大可以贡献90。

2、枚举n-90~90即可。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 10000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
char s[20];
vector<int> ans;
int main(){
int n;
scanf("%d", &n);
int cnt = 0;
for(int i = n - 90; i <= n; ++i){
if(i < 0) continue;
sprintf(s, "%d", i);
int len = strlen(s);
int sum = i;
for(int j = 0; j < len; ++j){
sum += s[j] - '0';
}
if(sum == n){
ans.push_back(i);
}
}
int l = ans.size();
printf("%d\n", l);
for(int i = 0; i < l; ++i){
if(i) printf(" ");
printf("%d", ans[i]);
}
printf("\n");
return 0;
}

  

最新文章

  1. react native 的图表开源组件react-native-chart-android
  2. WPF时间格式化
  3. 超简单,安卓模拟器手动root
  4. Hyper-V端口映射
  5. 360和QQ大战之我见
  6. 线性回归和批量梯度下降法python
  7. 2013年ACM湖南省赛总结
  8. Jquery几个比较实用,但又让很多人忽略的几个函数
  9. 【CodeForces】【321E】Ciel and Gondolas
  10. City Tour
  11. AOJ 0033 深度优先搜索
  12. UITableView的性能优化
  13. GreenDao 兼容升级,保留旧数据的---全方面解决方案
  14. Java不走弯路教程(3.用户验证与文件内容查询)
  15. Struts2 源码剖析 控制部分-----1
  16. php设计模式--简单介绍
  17. RequireJS - 个人小入门
  18. 使用themeleaf页面技术时,在JavaScript代码中使用for循环报错.....
  19. Tips and Tricks for Debugging in chrome
  20. 用rekit创建react项目

热门文章

  1. 洛谷 P3371 【模板】单源最短路径(弱化版) &amp;&amp; dijkstra模板
  2. 洛谷P1301 魔鬼之城 题解
  3. stack的使用-Hdu 1062
  4. hutoolJava工具类的使用
  5. oracle的decode、sign、nvl,case...then函数
  6. js数组去重解决方案
  7. day18-Python运维开发基础(单继承 / 多继承 / 菱形继承、类的多态)
  8. Codeforces Round #588 (Div. 2)D(思维,多重集)
  9. 监听EditView中的文本改变事件详解--转
  10. HTML标签,CSS简介