zoukankan      html  css  js  c++  java
  • Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) C. Classroom Watch

    地址:http://codeforces.com/contest/876/problem/C

    题目:

    C. Classroom Watch
    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 x written 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.

    思路:

      分析一下可以发现,x最多是9位数,所以x的每一位数字之和最大也就是100,。

      所以直接从n向下枚举100多就可以了。

     1 #include <bits/stdc++.h>
     2 
     3 using namespace std;
     4 
     5 #define MP make_pair
     6 #define PB push_back
     7 typedef long long LL;
     8 typedef pair<int,int> PII;
     9 const double eps=1e-8;
    10 const double pi=acos(-1.0);
    11 const int K=1e6+7;
    12 const int mod=1e9+7;
    13 
    14 int n;
    15 vector<int>vc;
    16 int main(void)
    17 {
    18     cin>>n;
    19     for(int i=n;i>0&&i>n-200;i--)
    20     {
    21         int x=i,ls=1e9,sum=i;
    22         while(x)
    23             sum+=x/ls,x%=ls,ls/=10;
    24         if(sum==n)
    25             vc.PB(i);
    26     }
    27     printf("%d
    ",vc.size());
    28     reverse(vc.begin(),vc.end());
    29     for(auto &x:vc)
    30         printf("%d ",x);
    31     return 0;
    32 }
  • 相关阅读:
    VisualSVN 4.0.11补丁原创发布
    用Advanced Installer制作DotNetBar for Windows Forms 12.0.0.1_冰河之刃重打包版详解
    树霉派4B换国内源注意事项
    StepShot4.3.0安装包_KeyGen发布
    NoSQL Manager for Cassandra 3.2.0.1 带Key
    NoSQL Manager for MongoDB 4.6.0.3 带key
    数值分析 三次样条插值及实现
    POJ 1753 Flip Game 暴力 深搜
    最短路问题 Dijkstra算法- 路径还原
    任意两点间的最短路问题 Floyd-Warshall算法
  • 原文地址:https://www.cnblogs.com/weeping/p/7680471.html
Copyright © 2011-2022 走看看