题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2063
题意:只输入一个m,表示共进行m轮游戏,每轮游戏都会提供给你一个只含有01的字符串,第一场游戏字符串长度为2,第二场尾3……输出? x y表示x位置和y位置的元素交换,! x y表示你认为x位置和y位置的元素相等(正确率要在80%以上)
解析:题目意思相当于你输出指令交换这个字符串里的元素,并猜交换后那两个位置的元素相等,那么我们直接对这个字符串进行排序,然后猜相邻的元素相等就好,这样猜的正确率比较高
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <ctime>
using namespace std;
const int maxn = 2*1e5+100;
int m;
int main()
{
scanf("%d",&m);
srand(0);
for(int n = 2;n<=m+1;n++)
{
for(int j=2;j<=n;j++)
{
for(int k=1;k<j;k++)
printf("? %d %d\n",j,k);
}
int ans = rand()%(n-1);
printf("! %d %d\n",ans+1,ans+2);
}
return 0;
}