题目
思路
打表找规律:
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;
}