問題の解決策 ARC099 D - Snuke Numbers

题目链接
题目链接2
题解
显然这是一道数论的题目..打表可以找出规律.
code:


#include "bits/stdc++.h"

using namespace std;

typedef long long ll;

double Snuke(ll x) {
    ll tmp = 0, c = x;
    while(c) {
        tmp += c % 10;
        c /= 10;
    }
    return 1.0 * x / tmp;
}

int main() {
    int K;
    cin >> K;
    ll res = 0, x = 1;
    while(K--) {
        double t1, t2;
        while(true) {
            t1 = Snuke(res + x), t2 = Snuke(res + x * 10);
            if(t1 <= t2) break;
            x *= 10;
        }
        res += x;
        printf("%lld\n", res);
    }
    return 0;
}

つづく...

猜你喜欢

转载自www.cnblogs.com/hnfms-jerry/p/arc099-abc101-D_Snuke_Numbers.html