F1. Nearest Beautiful Number (easy version)
预处理加二分
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 3;
#define int long long
set<int>cun1,cun2;
signed main()
{
//单个
for (int i=1;i<=9;i++)
{
int res = 0;
for (int j=0;j<=9;j++)
{
res = res*10+i;
cun1.insert(res);
}
}
//两个
int cou = pow(2,10);
for (int i=0;i<=9;i++)
{
for (int j=i+1;j<=9;j++)
{
for(int k =1 ;k <=10 ; k++)//位数
{
for (int h=0;h<(1<<k);h++)
{
int res = 0;
for (int m = k-1;m>=0;m--)
{
if (h>>m&1) res = res*10+i;
else res = res*10+j;
}
cun2.insert(res);
}
}
}
}
int t;
cin >> t;
while (t--)
{
int n, k;
cin >> n >> k;
if (k==1) cout<<*cun1.lower_bound(n)<<endl;
else cout<<*cun2.lower_bound(n)<<endl;
}
}