求助关于交互题
查看原帖
求助关于交互题
31646
Guitar_Jasmine楼主2020/6/16 21:20

RT,萌新第一次写正式交互题,但一直Wrong answer on test 1Wrong \ answer \ on \ test\ 1,自己也在本机里模拟了交互库,没什么问题,可能是哪里格式写挂了,求走过路过帮忙看看格式/kel

代码如下(注释掉的是模拟交互库):

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<ctime>

using namespace std;

const int N=1000;
int n,p[N+9];

int Get(int x,int y)
{
	printf("? %d %d\n",x,y);
	fflush(stdout);
	int k;
	scanf("%d",&k);
	return k;
//	return p[x]|p[y];
}

void init()
{
	scanf("%d",&n);
}

bool check(int x)
{
	int A=2047;
	for (int _=1;_<=30;_++)
	{
		A&=Get(x,rand()%n);
		if(A==0) return 1;
	}
	return 0;
}

void prework()
{
	srand(time(0));
	n=rand()%100+1;
	while(n<3) n=rand()%10+1;
	for (int i=1;i<=n;i++)
		p[i]=i-1;
	random_shuffle(p+1,p+1+n);
	printf("%d\n",n);
	for (int i=1;i<=n;i++)
		printf("%d ",p[i]);puts("");
}

void work()
{
	int A=1,B=2,now=Get(A,B);
	for (int i=3;i<=n;i++)
	{
		int C=Get(A,i);
		if(C<now) B=i,now=C;
		else if(C==now) A=i,now=Get(A,B);
	}
	int pos=check(A)?A:B;
//	printf("pos:%d\n",pos);
	printf("! ");
	for (int i=1;i<n;i++)
		printf("%d ",Get(pos,i));
	printf("%d\n",Get(pos,n)); 
	fflush(stdout);
}

int main()
{
	srand(time(0));
//	prework();
	init();
	work();
	return 0;
}
2020/6/16 21:20
加载中...