这道题感觉挺水的,纯模拟,10个点全过了,拿走不谢

P3955 [NOIP2017 普及组] 图书管理员

fengyucan @ 2019-07-01 21:34:20

include<cstdio>

include<algorithm>

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 fengyucan @ 2019-07-10 22:49:29

谢谢


by seino @ 2019-07-11 20:13:29

我已经做废了。。。


上一页 |