fengyucan @ 2019-07-01 21:34:20
using namespace std;
const int N=1100;
int n1[N],qq[N],q1[N],ax[N];
int n,q,ans;
int f(int x,int y){
int i=1;
for(int j=1;j<=y;++j)i*=10;
x=x%i;
return x;
}
bool f1(int x,int y){
int fx;
for(int i=1;i<=n;++i){
fx=f(n1[i],x);
if(fx==y) return true;
}
return false;
}
int ff1(int x,int y){
int a[N],ffx,num=0;
for(int i=1;i<=n;++i){
ffx=f(n1[i],x);
if(ffx==y){
++num;
a[num]=n1[i];
}
}
sort(a+1,a+num+1);
ffx=a[1];
return ffx;
}
int main(){
// freopen("librarian.in","r",stdin); //freopen("librarian.out","w",stdout);
scanf("%d%d",&n,&q);
for(int i=1;i<=n;++i)scanf("%d",&n1[i]);
for(int i=1;i<=q;++i){
scanf("%d",&qq[i]);
scanf("%d",&q1[i]);
}
ans=0;
for(int i=1;i<=q;++i){
++ans;
if(!f1(qq[i],q1[i]))ax[ans]=0;
else{
int ff1a=ff1(qq[i],q1[i]);
ax[ans]=ff1a;
}
}
for(int i=1;i<=q;++i){
if(ax[i]==0) printf("-1\n");
else printf("%d\n",ax[i]);
}
return 0;
}
by _H1kar1 @ 2019-07-01 21:36:07
您的markdown用的我头皮发麻
@fengyucan
另,如果觉得自己打的很好建议提交题解
by 小小小朋友 @ 2019-07-01 21:38:01
推荐P3920(逃
by XMK_萌新 @ 2019-07-01 21:39:52
以及这题(光速逃
by 览遍千秋 @ 2019-07-01 21:42:04
火钳刘明
by 小小小朋友 @ 2019-07-01 21:49:12
找到了一个好题
by MILLOPE @ 2019-07-01 21:54:52
by MILLOPE @ 2019-07-01 21:55:32
您这个代码粘的有点优秀
by VenusM1nT @ 2019-07-01 21:55:33
发题解 plz
顺便窝觉得
by π酱 @ 2019-07-01 22:12:54
强烈建议楼主做一下P4473
我觉得您一定可以跑到200ms以内qwq
by foxdemon @ 2019-07-02 09:13:41
orzorz