zoukankan      html  css  js  c++  java
  • Codeforces Round #643 (Div. 2) A. Sequence with Digits(暴力)

    Let's define the following recurrence:

    an+1=an+minDigit(an)maxDigit(an).an+1=an+minDigit(an)⋅maxDigit(an).

    Here minDigit(x)minDigit(x) and maxDigit(x)maxDigit(x) are the minimal and maximal digits in the decimal representation of xx without leading zeroes. For examples refer to notes.

    Your task is calculate aKaK for given a1a1 and KK .

    Input

    The first line contains one integer tt (1t10001≤t≤1000 ) — the number of independent test cases.

    Each test case consists of a single line containing two integers a1a1 and KK (1a110181≤a1≤1018 , 1K10161≤K≤1016 ) separated by a space.

    Output

    For each test case print one integer aKaK on a separate line.

    Example
    Input
    Copy
    8
    1 4
    487 1
    487 2
    487 3
    487 4
    487 5
    487 6
    487 7
    
    Output
    Copy
    42
    487
    519
    528
    544
    564
    588
    628
    按题目说的模拟,特别地,一个数里出现0的时候直接输出当前数并break。
    #include <bits/stdc++.h>
    using namespace std;
    long long a,k;
    int main()
    {
        int t;
        cin>>t;
        while(t--)
        {
            cin>>a1>>k;
            int cnt;
            if(k==1)
            {
                cout<<a<<endl;
                continue;
            }
            for(cnt=2;cnt<=k;cnt++)
            {
                int mmax=-1,mmin=10;
                long long temp=a;
                while(temp)//拆分数字
                {
                    int dig=temp%10;
                    mmax=max(mmax,dig);
                    mmin=min(mmin,dig);
                    temp/=10;
                }
                if(k==cnt)
                {
                    cout<<a+mmax*mmin<<endl;
                }
                else if(mmin==0)//出现0了 累加之后还是0 因此直接输出 终止循环
                {
                    cout<<a+mmax*mmin<<endl;
                    break;
                }
                else a+=mmax*mmin;
            }
        }
    }


  • 相关阅读:
    机器学习-正则化方法
    机器学习-回归算法
    机器学习算法一
    机器学习概览
    tensorflow机器学习初接触
    tensorflow决策树初接触
    tensorflow语法
    tensorflow第一个例子简单实用
    Hyperledger Fabric 1.0架构入门
    结合《XXXX需求征集系统》分析可用性和可修改性战术
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/12902759.html
Copyright © 2011-2022 走看看