QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#637471#8239. Mysterious TreewzxtslCompile Error//C++234.0kb2024-10-13 12:59:232024-10-13 12:59:25

Judging History

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

  • [2024-10-13 12:59:25]
  • 评测
  • [2024-10-13 12:59:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define For(i,j,k) for (int i=(j);i<=(k);i++)
#define rof(i,j,k) for (int i=(j);i>=(k);i--)
#define ull unsigned long long
#define lowbit(x) ((x)&(-(x)))
#define PII pair<int,int>
#define int long long
#define endl "\n"
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
const int mod = 998244353;
const double eps = 1e-9;
const int N=2e6+7;
int n,m;
void solve(){
	cin>>n;
    if(n%2==0){
        int cnt=0,i,j,num;
        for(int k=1;k<=n;k+=2){
            cout<<"? "<<k<<" "<<k+1<<endl;
            cout.flush();
            cin>>num;
            if(num==1) cnt++,i=k,j=k+1;
        }
        if(cnt!=1){
            cout<<"! 1"<<endl;
            return ;
        }
        int a[3];
        int cn=0;
        for(int k=1;k<=n;k++){
            if(k!=i&&k!=j){
                a[++cn]=k;
            }
        }
        cout<<"? "<<a[1]<<" "<<i<<endl;
        cout.flush();
        cin>>num;
        if(num==1){
            cout<<"? "<<a[2]<<" "<<i<<endl;
            cout.flush();
            cin>>num;
            if(num==1){
                cout<<"! 2"<<endl;
                return ;
            }else{
                cout<<"! 1"<<endl;
            }
        }else{
            cout<<"? "<<a[1]<<" "<<j<<endl;
            cout.flush();
            cin>>num;
            if(num==1){
                cout<<"? "<<a[2]<<" "<<j<<endl;
                cout.flush();
                cin>>num;
                if(num==1){
                    cout<<"! 2"<<endl;
                    return ;
                }else{
                    cout<<"! 1"<<endl;
                    return ;
                }
            }else{
                cout<<"! 1"<<endl;
                return ;
            }
        }
    }else{
        int cnt=0,i,j,num;
        for(int k=1;k<=n&&k+1<=n;k+=2){
            cout<<"? "<<k<<" "<<k+1<<endl;
            cout.flush();
            cin>>num;
            if(num==1) cnt++,i=k,j=k+1;
        }
        if(cnt==0){
            cout<<"? "<<n<<" "<<1<<endl;
            cout.flush();
            cin>>num;
            if(num==1) cnt++;
            cout<<"? "<<n<<" "<<2<<endl;
            cout.flush();
            cin>>num;
            if(num==1) cnt++;
            cout<<"? "<<n<<" "<<3<<endl;
            cout.flush();
            cin>>num;
            if(num==1) cnt++;
            if(cnt==3){
                cout<<"! 2"<<endl;
                return ;
            }else{
                cout<<"! 1"<<endl;
                return ;
            }
        }else if(cnt==1){
            for(int k=1;k<=n;k++){
            if(k!=i&&k!=j){
                a[++cn]=k;
            }
            }
            cout<<"? "<<a[1]<<" "<<i<<endl;
            cout.flush();
            cin>>num;
            if(num==1){
                cout<<"? "<<a[2]<<" "<<i<<endl;
                cout.flush();
                cin>>num;
                if(num==1){
                    cout<<"! 2"<<endl;
                    return ;
                }else{
                    cout<<"! 1"<<endl;
                }
            }else{
                cout<<"? "<<a[1]<<" "<<j<<endl;
                cout.flush();
                cin>>num;
                if(num==1){
                    cout<<"? "<<a[2]<<" "<<j<<endl;
                    cout.flush();
                    cin>>num;
                    if(num==1){
                        cout<<"! 2"<<endl;
                        return ;
                    }else{
                        cout<<"! 1"<<endl;
                        return ;
                    }
                }else{
                    cout<<"! 1"<<endl;
                    return ;
                }
            }
        }else{
            cout<<"! 1"<<endl;
            return ;
        }
    }
}
signed main(){
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}
}

詳細信息

answer.code: In function ‘void solve()’:
answer.code:103:17: error: ‘a’ was not declared in this scope
  103 |                 a[++cn]=k;
      |                 ^
answer.code:103:21: error: ‘cn’ was not declared in this scope; did you mean ‘cnt’?
  103 |                 a[++cn]=k;
      |                     ^~
      |                     cnt
answer.code:106:25: error: ‘a’ was not declared in this scope
  106 |             cout<<"? "<<a[1]<<" "<<i<<endl;
      |                         ^