QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#858198 | #8939. Permutation | zhouyuxuan3501 | WA | 0ms | 3584kb | C++14 | 764b | 2025-01-16 14:55:11 | 2025-01-16 14:55:26 |
Judging History
answer
#include<iostream>
#include<cmath>
using namespace std;
const double phi=0.6180339887;
int T,n;
int W(int a,int b)
{
int h;
cout<<"? "<<a<<" "<<b<<endl;
cin>>h;
return h;
}
int C(int a,int b,int p)
{
int h;
if(a==b)return a;
if(!p)p=W(a,b);
if(a+1==b)return a+b-p;
int l=max(2.0,(b-a+1)*phi);
if(p<a+l)
{
h=W(a,a+l-1);
if(h==p)return C(a,a+l-1,p);
return C(a+l,b,0);
}
else
{
h=W(a+l,b);
if(h==p)return C(b-l+1,b,p);
return C(a,b-l,0);
}
}
int main()
{
ios::sync_with_stdio(0);
int h;
cin>>T;
while(T--)
{
cin>>n;
h=C(1,n,0);
cout<<"! "<<h<<endl;
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3584kb
input:
3 5 3 2 5 6 6 5 3
output:
? 1 5 ? 1 3 ? 4 5 ! 4 ? 1 6 ? 4 6 ? 1 3 ? 3 3
result:
wrong answer Integer 3 violates the range [4, 6] (test case 2)