80分求助!!!

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

bjqxszx_zhongqide @ 2024-10-15 21:33:34

#include<bits/stdc++.h>
using namespace std;
int poww(int a,int b){
    int ans = 1;
    for(int i=1;i<=b;i++){
        ans*=a;
    }
    return ans;
}
int main(){
    int n,q,minn=1000000001;
    cin>>n>>q;
    int a[n],b[q],c[q];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<q;i++){
        cin>>b[i]>>c[i];
        for(int j=0;j<q;j++){
            if((a[j]%poww(10,b[i]))==c[i]){
                if(a[j]<minn){
                    minn=a[j];
                }
            }
        }
        if(minn==1000000001){
            cout<<-1<<endl;
        }else{
            cout<<minn<<endl;
        }
        minn=1000000001;
    }
    return 0;
}

by tsgaoyunxuan @ 2025-01-08 22:08:44

@bjqxszx_zhongqide,你试一下我的代码,可以AC的。

#include<bits/stdc++.h>
using namespace std;
int n,q,book[7000],len[7000],num[7000];
int main(){
    cin>>n>>q;
    for(int i=1;i<=n;i++){
        cin>>book[i];
    }
    for(int i=1;i<=q;i++){
        cin>>len[i]>>num[i];
        int tmp=pow(10,len[i]),min=10000001;
        for(int j=1;j<=n;j++){
            if(book[j]%tmp==num[i]&&book[j]<min){
                min=book[j];
            }
        }
        if(min!=10000001){
            cout<<min<<endl;
        }
        else {
            cout<<-1<<endl;
        }
    }
    return 0;
}

希望你可以互关哦


by bjqxszx_zhongqide @ 2025-01-09 19:25:50

Thank you


|