求助
查看原帖
求助
193541
羚羊WANG楼主2022/6/17 00:12
#include<bits/stdc++.h>
#define ll long long
#define fr(i,j,k) for(register int i=j;i<=k;++i)
#define rf(i,j,k) for(register int i=j;i>=k;--i)
#define foredge(i,j) for(register int i=head[j];i;i=e[i].nxt)
#define randfind(l,r) (rand()%((r)-(l)+1)+(l))
#define pb push_back
#define Times printf("Time:%.3lf\n",clock()/CLOCKS_PER_SEC)
using namespace std;
inline int read(){
	int x=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
inline ll Read(){
	ll x=0;
	bool f=0;
	char c=getchar();
	while(!isdigit(c)) f|=(c=='-'),c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f?-x:x;
}
inline void write(int x){
    if(x<0){putchar('-');x=-x;}
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
inline void writeln(int x){write(x); puts("");}
inline void writepl(int x){write(x); putchar(' ');}
inline void Write(ll x){
    if(x<0){putchar('-'); x=-x;}
    if(x>9)Write(x/10);
    putchar(x%10+'0');
}
inline void Writeln(ll x){Write(x); puts("");}
inline void Writepl(ll x){Write(x); putchar(' ');}
int n;
int a[1010];
inline void query2(int x,int y){
	cout<<"!"<<' '<<x<<' '<<y<<endl;
	fflush(stdout);
}
inline void query1(int x,int y,int z){
	cout<<"?"<<' '<<x<<' '<<y<<' '<<z<<endl;
	fflush(stdout);
}
inline void check(int x,int y,int z){
	int maxn=-1,X1,id1,id2;
	query1(x,x,y);
	cin>>X1;
//	cout<<"**"<<x<<' '<<y<<' '<<X1<<endl;
	if(X1>maxn){
		maxn=X1;
		id1=x;
		id2=y;
	}
	query1(x,x,z);
	cin>>X1;
//	cout<<"**"<<x<<' '<<z<<' '<<X1<<endl;
	if(X1>maxn){
		maxn=X1;
		id1=x;
		id2=z;
	}
	query1(z,z,y);
	cin>>X1;
//	cout<<"**"<<z<<' '<<y<<' '<<X1<<endl;
	if(X1>maxn){
		maxn=X1;
		id1=z;
		id2=y;
	}
	query2(id1,id2);
	return;
}
int id1,id2;
inline void find(int &id1,int &id2,int x,int y){
	int X1,X2,X3,X4;
	int maxn;
	query1(id1,id2,x);
	cin>>X1;
	query1(id2,x,y);
	cin>>X2;
	query1(x,y,id1);
	cin>>X3;
	query1(y,id1,id2);
	cin>>X4;
//	query1(2,4,5);
//	int X1;
//	cin>>X1;
//	cout<<"**"<<X1<<endl;
	maxn=max(max(max(X1,X2),X3),X4);
	if(X1==maxn && X2==maxn){
		id1=x;
		return;
	}
	if(X2==maxn && X3==maxn){
		id1=x;
		id2=y;
		return;
	}
	if(X3==maxn && X4==maxn){
		id2=y;
		return;
	}
	if(X1==maxn && X3==maxn){
		id2=x;
		return;
	}
	if(X1==maxn && X4==maxn){
		return;
	}
	if(X2==maxn && X4==maxn){
		id1=y;
		return;
	}
}
inline void work(){
	cin>>n;
	if(n==1){
		query2(1,1);
		return;
	}
	if(n==2){
		query2(1,2);
		return;
	}
	if(n==3){
		check(1,2,3);
		return;
	}
	if(n%2==0){
		id1=1;
		id2=2;
		for(int i=3;i<=n;i+=2) find(id1,id2,i,i+1);
		query2(id1,id2);
		return;
	}
	id1=1;
	id2=2;
	for(int i=3;i<=n-1;i+=2) find(id1,id2,i,i+1);
	check(id1,id2,n);
	return;
}
inline void init(){
	int t;
	cin>>t;
	while(t--) work();
}
int main(){
	init();
    // printf("\nTIME:%.3lf",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

2022/6/17 00:12
加载中...