首页 > 其他分享 >abc101d<打表,数学>

abc101d<打表,数学>

时间:2024-01-15 15:48:11浏览次数:31  
标签:10 int double LL abc101d base ans

题目

D - Snuke Numbers

思路

打表找规律:

void bf(int n)
{
    vector<int> ans;
    double minn = double(n) / get(n);
    for (int i = n - 1; i >= 1; i --)
    {
        double t = double(i) / get(i);
        if (t <= minn + 1e-9)
        {
            minn = t;
            ans.push_back(i);
        }
    }

    int cnt = ans.size();
    for (int i = 0; i < ans.size(); i ++)
    {
        printf("%03d  %d\n", i+1, ans[cnt - i - 1]);
    }
}

代码

点击查看代码
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using LL = long long;

double s(LL x)
{
    int res = 0;
    LL y = x;
    while (x)
        res += (x % 10), x /= 10;
    return (1.0 * y) / (1.0 * res);
}

void solv()
{
    int n;
    cin >> n;

    LL ans = 0;
    LL base = 1;
    while (n--)
    {
        while (true)
        {
            if (s(ans + base) > s(ans + base * 10))
                base *= 10;
            else
                break;
        }
        ans += base;
        cout << ans << '\n';
    }
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    // cin >> T;
    while (T--)
        solv();
    return 0;
}

标签:10,int,double,LL,abc101d,base,ans
From: https://www.cnblogs.com/o2iginal/p/17965484

相关文章