0
点赞
收藏
分享

微信扫一扫

1634D. Finding Zero

紫荆峰 2022-03-22 阅读 27
c++算法

D. Finding Zero
构造,我们设a,b,c里面有最大值和最小值在这里插入代码片,然后再从中找到二者

#include<bits/stdc++.h>
using namespace std;
const int N = 2e6+7;
int ask(int a,int b,int x)
{
	cout<<"? "<<a<<" "<<b<<" "<<x<<endl;
	cin>>x;
	return x;
}
void print(int a,int b)
{
	cout<<"! ";
	cout<<a<<" ";
	cout<<b<<endl;
}
signed main()
{
	int t;
	cin>>t;
	while (t--)
	{
		int n;
		cin>>n;
		int x = ask(1,2,3);
		int a = 1,b = 2,c = 3;
		for (int i=4;i<=n;i++)
		{
			int u = ask(a,b,i);
			int v = ask(a,c,i);
			if (u<v)
			{
				if (x<v) b = i,x = v;
			}
			else 
			{
				if (x<u) c = i,x = u;
			}
		}
		int r = 1;
		while (r==a||r==b||r==c) r++;
		int A = ask(r,b,c);
		int B = ask(a,r,c);
		int C = ask(a,b,r);
		if (A==x) print(b,c);
		else if (B==x) print(a,c);
		else print(a,b);
	}
}
举报

相关推荐

0 条评论