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 }
  • 相关阅读:
    读书笔记 之《Thinking in Java》(对象、集合、异常)
    ArrayList 和 LinkedList的执行效率比较
    Hybris CronJob.
    C# 中的treeview绑定数据库(递归算法)
    identity_insert---实验性插入大批量数据和分页存储过程
    SQL Server 存储过程
    PL/SQL 在64位机上不能使用的问题解决
    登陆Oracle11g的企业管理器
    SQL在oracle和SQLserver将查询结果创建为新表的不同之处
    介绍一下内联、左联、右联
  • 原文地址:https://www.cnblogs.com/weeping/p/7680471.html
Copyright © 2011-2022 走看看