zoukankan      html  css  js  c++  java
  • codeforces Round #441 C Classroom Watch【枚举/注意起点】

    C.
    time limit per test
    1 second
    memory limit per test
    512 megabytes
    input
    standard input
    output
    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.

    Input

    The first line contains integer n (1 ≤ n ≤ 109).

    Output

    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.

    Examples
    input
    21
    output
    1
    15
    input
    20
    output
    0
    Note

    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[100];
    int putu(int n,int i)
    {
        int p=i;
        while(p)
        {
            i+=p%10;
            p/=10;
        }
        return i==n;
    }
    int main(void)
    {
        int n,ans=0;
        scanf("%d",&n);
        for(int i=max(n-81,0);i<=n;i++)
        {
            if(putu(n,i))
            {
                save[ans++]=i;
            }
        }
        printf("%d
    ",ans );
        if(ans>0)
        {
            for(int i=0;i<ans;i++)
                printf("%d
    ",save[i] );
        }
        return 0;
    }
    View Code
  • 相关阅读:
    ssh-keygen的使用方法(无密码访问)
    ubuntu solute two different terminals cmd
    ubuntu 查看系统是32位还是64位
    pyplot 绘图与可视化
    python 正则表达式的处理
    python&pandas 与mysql 连接
    Ubuntu 11.10 H3C iNode 客户端安装
    Vijos1055(极大子矩阵)
    Vijos1055(极大子矩阵)
    luoguP2701 [USACO5.3]巨大的牛棚Big Barn(极大子矩阵)
  • 原文地址:https://www.cnblogs.com/Roni-i/p/7679090.html
Copyright © 2011-2022 走看看