QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#682042#9162. COVID testsRDFZchenyyCompile Error//C++144.0kb2024-10-27 13:38:102024-10-27 13:38:11

Judging History

你现在查看的是最新测评结果

  • [2024-10-27 13:38:11]
  • 评测
  • [2024-10-27 13:38:10]
  • 提交

answer

#include<bits/stdc++.h>

using ld=long double;

int n; ld p;
int T;
int a[1005]; char c;
char b[1005];

bool ask(int l,int r){
    std::cout<<'Q'<<' ';
    for(int j=1;j<=n;j++){
        std::cout<<(char)((j>=l&&j<=r)+'0');
    }
    std::cout<<std::endl;
    std::cin>>c;
    return c=='P';
}
// bool ask(int l,int r){
//     for(int i=l;i<=r;i++){
//         if(b[i]=='1') return true;
//     }
//     return false;
// }

void run(){
    memset(a,0,sizeof(a));
    for(int i=1;i<=n;i++){
        std::cout<<'Q'<<' ';
        for(int j=1;j<=n;j++){
            std::cout<<(char)((j==i)+'0');
        }
        std::cout<<std::endl;
        std::cin>>c;
        if(c=='P') a[i]=1;
    }
    std::cout<<'A'<<' ';
    for(int i=1;i<=n;i++){
        std::cout<<a[i];
    }
    std::cout<<std::endl; std::cin>>c;
    return;
}

namespace Sol1{
    void query(int l,int r){
        if(l==r){
            a[l]=1; return;
        }
        int mid=(l+r)>>1;
        if(ask(l,mid)){
            query(l,mid);
            if(ask(mid+1,r)){
                query(mid+1,r);
            }
        }else{
            query(mid+1,r);
        }
        return;
    }

    void run(){
        memset(a,0,sizeof(a));
        if(ask(1,n)) query(1,n);
        std::cout<<'A'<<' ';
        for(int i=1;i<=n;i++){
            std::cout<<a[i];
        }
        std::cout<<std::endl; std::cin>>c;
        return;
    }
}

namespace Sol9{
    void query(int l,int r){
        if(l==r){
            a[l]=1; return;
        }
        int mid=(l+r)>>1;
        if(ask(l,mid)){
            query(l,mid);
            if(ask(mid+1,r)){
                query(mid+1,r);
            }
        }else{
            query(mid+1,r);
        }
        return;
    }

    void run(){
        memset(a,0,sizeof(a));
        for(int i=1;i<=n-1;i+=3){
            if(ask(i,i+2)) query(i,i+2);
        }
        a[n]=ask(n,n);
        std::cout<<'A'<<' ';
        for(int i=1;i<=n;i++){
            std::cout<<a[i];
        }
        std::cout<<std::endl; std::cin>>c;
        return;
    }
}

namespace Ex{
	int guess;
    int pre[1005][2];
    ld f[1005][2];
    ld fpow(ld a,int b){
        ld ret=1;
        for(;b;b>>=1,a*=a) if(b&1) ret*=a;
        return ret;
    }
    void init(){
        f[1][0]=1; f[1][1]=0; 
        for(int i=2;i<=n;i++){
            f[i][0]=f[i][1]=1e18;
            for(int j=1;j<=i-1;j++){
                ld p1=((ld)1.0-fpow((ld)1.0-p,j));
                ld p2=p1/((ld)1.0-fpow((ld)1.0-p,i));
                if((ld)1.0+p1*(f[i-j][0]+f[j][1])+(1-p1)*f[i-j][0]<f[i][0]){
                    pre[i][0]=j;
                    f[i][0]=(ld)1.0+p1*(f[i-j][0]+f[j][1])+(1-p1)*f[i-j][0];
                }
                if((ld)1.0+p2*(f[i-j][0]+f[j][1])+(1-p2)*f[i-j][1]<f[i][1]){
                    pre[i][1]=j;
                    f[i][1]=(ld)1.0+p2*(f[i-j][0]+f[j][1])+(1-p2)*f[i-j][1];
                }
            }
            if(f[i][0]>1+((ld)1.0-fpow((ld)1.0-p,i))*f[i][1]){
                pre[i][0]=0;
                f[i][0]=1+((ld)1.0-fpow((ld)1.0-p,i))*f[i][1];
            }
        }
        return;
    }
    void query(int l,int r,int o){
        if(l==r){
            if(o==1) a[l]=1,sol--;
            else a[l]=ask(l,l),sol-=a[l];
            return;
        }
        int x=r-l+1;
		if(guess<=0) Sol1::query(l,r);
		else if(pre[x][o]==0){
            if(ask(l,r)) query(l,r,1);
        }else{
            int y=pre[x][o];
            if(ask(l,l+y-1)) query(l,l+y-1,1),query(l+y,r,0);
            else query(l+y,r,o);
        }
        return;
    }
    void run(){
        memset(a,0,sizeof(a));
        query(1,n,0);
		guess=ceil(n*p)+5;
        std::cout<<'A'<<' ';
        for(int i=1;i<=n;i++){
            std::cout<<a[i];
        }
        std::cout<<std::endl; std::cin>>c;
        return;
    }
}

int main(){
    std::cin>>n>>p>>T;
    // std::cin>>(b+1);
    Ex::init();
    for(int i=1;i<=T;i++) Ex::run();
    return 0;
}

Details

answer.code: In function ‘void Ex::query(int, int, int)’:
answer.code:140:29: error: ‘sol’ was not declared in this scope
  140 |             if(o==1) a[l]=1,sol--;
      |                             ^~~
answer.code:141:32: error: ‘sol’ was not declared in this scope
  141 |             else a[l]=ask(l,l),sol-=a[l];
      |                                ^~~