[ABC333C] Repunit Trio

· · 题解

思路

用一个数组 a 存有着 1 个 1 到 12 个 1 的数组,然后用三重循环把他们的所有可能存在一个 set 当中,最后 auto 遍历整个数组遍历到第 n 个数时,输出即可。

Code

#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define IO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
const int E=1e6+5;
ll n,cnt;
ll a[E]={0,1,11,111,1111,11111,111111,1111111,11111111,111111111,1111111111,11111111111,111111111111};
int main(){
    IO;
    set <ll> ans;
    cin >>n;
    for(int i=1;i<=12;i++)
        for(int j=1;j<=12;j++)
            for(int k=1;k<=12;k++)
                ans.insert(a[i]+a[j]+a[k]);
    for(auto v:ans){
        cnt++;
        if(cnt==n){
            cout <<v;
            return 0;
        }
    }
    return 0;
}