QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#748350 | #8239. Mysterious Tree | CSQ# | WA | 1ms | 3576kb | C++17 | 1023b | 2024-11-14 20:08:02 | 2024-11-14 20:08:05 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x); (int) (x).size()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
int ask(int v,int u){
cout<<"? "<<v<<" "<<u<<endl;
int x;
cin>>x;
return x;
}
int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
bool ok = 0;
int ans = 1;
for(int i=1;i+1<=n;i+=2){
if(!ask(i,i+1))continue;
ok = 1;
vector<int>a;
for(int j=1;j<=n;j++){
if(j != i && j!= i+1)a.push_back(j);
}
ans = 1;
if(ask(i,a[0])){
if(ask(i,a[1]))ans = 2; //star
}else{
if(ask(i+1,a[0])){
if(ask(i+1,a[1]))ans = 2; //star
}
}
}
if(!ok && n&1){
ans = 1;
if(ask(n-1,n)){
if(ask(n-1,1)){
if(ask(n-1,2))ans = 2; //star
}else{
if(ask(n,1)){
if(ask(n,2))ans = 2; //star
}
}
}
}
cout<<"! "<<ans<<endl;
}
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3576kb
input:
2 4 1 0 1 0 1
output:
? 1 2 ? 1 3 ? 2 3 ? 2 4 ? 3 4 ? 3 1
result:
wrong answer Too many queries , n = 4 , now_q 6 (test case 1)