题意:已知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;
}

  

CodeForces - 876C Classroom Watch (枚举)的更多相关文章

  1. Codeforces 876C Classroom Watch:枚举

    题目链接:http://codeforces.com/contest/876/problem/C 题意: 定义函数:f(x) = x + 十进制下x各位上的数字之和 给你f(x)的值(f(x) < ...

  2. codeforces 895A Pizza Separation 枚举

    codeforces 895A Pizza Separation 题目大意: 分成两大部分,使得这两部分的差值最小(注意是圆形,首尾相连) 思路: 分割出来的部分是连续的,开二倍枚举. 注意不要看成0 ...

  3. Codeforces C. Classroom Watch

    C. Classroom Watch time limit per test 1 second memory limit per test 512 megabytes input standard i ...

  4. Educational Codeforces Round 61 C 枚举 + 差分前缀和

    https://codeforces.com/contest/1132/problem/C 枚举 + 差分前缀和 题意 有一段[1,n]的线段,有q个区间,选择其中q-2个区间,使得覆盖线段上的点最多 ...

  5. Vasya and Beautiful Arrays CodeForces - 354C (数论,枚举)

    Vasya and Beautiful Arrays CodeForces - 354C Vasya's got a birthday coming up and his mom decided to ...

  6. CodeForces 617C【序枚举】

    题意: 有两个点喷水,有很多个点有花,给出坐标. 求使得每个花都可以被喷到,两个喷水的半径的平方的和最小是多少. 思路: 枚举其中一个喷水的最大半径. 坑: 这题我贪心的思路有很大问题.一开始也是想这 ...

  7. codeforces 613B B. Skills(枚举+二分+贪心)

    题目链接: B. Skills time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  8. CodeForces 158DIce Sculptures(枚举)

    一个暴力的枚举,枚举组成正多边形需要对应覆盖原先的几条边,范围为(1,n/3),然后维护最大值就可以了,注意初始化为-inf. #include<stdio.h> #include< ...

  9. Array and Segments (Easy version) CodeForces - 1108E1 (暴力枚举)

    The only difference between easy and hard versions is a number of elements in the array. You are giv ...

随机推荐

  1. Pandas 性能优化 学习笔记

    摘要 本文介绍了使用 Pandas 进行数据挖掘时常用的加速技巧. 实验环境 import numpy as np import pandas as pd print(np.__version__) ...

  2. 质因数分解(0)<P2012_1>

    质因数分解 (prime.cpp/c/pas) [问题描述] 已知正整数n是两个不同的质数的乘积,试求出较大的那个质数. [输入] 输入文件名为prime.in. 输入只有一行,包含一个正整数n. [ ...

  3. mysql cmmand not found

    https://www.cnblogs.com/yangzigege/p/8337393.html

  4. Unity初步 基本拼图实现

    using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; ...

  5. 1004 Counting Leaves (30分) DFS

    1004 Counting Leaves (30分)   A family hierarchy is usually presented by a pedigree tree. Your job is ...

  6. IntelliJ IDEA常用快捷键大全

    如果想要非常高效的使用IDEA这款工具,应该掌握图中已被标记的快捷键. 另: 代码实时模板生成:psvm/sout/ifn等 按Tab键快速生成模板. 转载请保留或注明出处:http://www.cn ...

  7. keil条件断点

    http://www.keil.com/support/man/docs/uv4/uv4_db_dbg_breakpnts.htm Target Device does not support con ...

  8. 树莓派4B踩坑指南 - (2)安装系统及初始化

    安装系统及初始化 格式化TF卡:SDFormatter 4.0.如果需要换系统,则必须先烧录进一个空img,然后再格式化! 烧录系统:Win32DiskImager-0.9.5 更改默认密码:账号pi ...

  9. centos7一步一步搭建docker nginx 及重点讲解

    系统环境:centos7.7 (VMware中) images版本:nginx:latest (截止2020.01.10最新版) 1.拉取镜像 docker pull nginx 2.启动nginx容 ...

  10. 理解JS中的回调(Callback)函数

    今天写代码时写了一个函数,想实现Nodejs查询pgSQL的数据查出来并把结果作为返回值,结果发现拿不到这个值,查了下资料才恍然大悟,这是Nodejs的最大特性--非阻塞! 查询数据操作作为比较消耗资 ...