题意

有个长度为n的排列p,[0,1,2,...n-1],你可以进行至多2*n次询问,每次询问两个i,j,返回gcd(pi,pj),让你在规定时间内猜出0在哪两个位置之一

思路

这是一道交互题,询问的上限是2n次

通过三个数,可以去除掉一个不是0的数

对三个数进行以下询问,gcd(a,i),gcd(b,i)

如果gcd(a,i) != gcd(b,i),那么其中a,b小的被i取代,因为a,b中假如有0,那么一定是大的数,那么小的数一定不是0

如果gcd(a,i) == gcd(b,i),那么跳过i,因为假如i是0,因为数列每个数都不同,所必不可能相等

那么for一遍数组,每次和当前位置i进行两次询问,最多2
n的限制内就可以筛选出0可能存在的位置p,q

代码

#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
const int N = 2e4 + 10;
int n, t = 1;
long long a[N], b[N];
int pw[N];
int l[N], cnt[N];
const int mod = 998244353;
map<int, int> mp;
int v[N]; int ask(int x, int y) {
cout << "? " << x << ' ' << y << endl;
int u;
cin >> u;
return u;
} void ok(int x, int y) {
cout << "! " << x << ' ' << y << endl;
int u;
cin >> u;
} void run() {
cin >> n;
int p = 1, q = 2;
for (int i = 3; i <= n; i++) {
int r1 = ask(p, i), r2 = ask(q, i);
if (r1 < r2) {
p = i;
}
if (r1 > r2) {
q = i;
} }
ok(q, p); } int main() {
srand(time(0));
cin >> t;
while (t--)
run();
return 0;
}

最新文章

  1. 《Paxos Made Simple》翻译
  2. .this语句指的是什么
  3. c语言-&gt;和 .
  4. Mac 安装 home Brew以及 XCTool的过程记录
  5. 三、第一个Struts2应用案例(编码步骤)
  6. HTML、JS、CSS之特殊字符
  7. IntelliJ IDEA “Finds duplicated code”提示如何关闭
  8. IDEA类文件不编译问题
  9. WKWebView 官方文档
  10. [GXOI/GZOI2019]与或和
  11. Android中 Git 使用中几个概念
  12. System.Collections里的一些接口
  13. InheritParasitic.js
  14. Python - 列表解析式
  15. codeforces365B
  16. Java8 异步编排类CompletableFuture
  17. K8S笔记
  18. 【LOJ】#2117. 「HNOI2015」实验比较
  19. Redis的简介
  20. windows10 装linux子系统

热门文章

  1. 企业使用erp系统的好处及解决了什么问题?
  2. 文件内再分类到各txt文件
  3. 洛谷P2866 [USACO06NOV]Bad Hair Day S (单调栈)
  4. Hive之命令
  5. python-D2-计算机与编程语言
  6. laravel config()获取null
  7. golang中的变量阴影
  8. 18.-cookies和session
  9. 第三方代开的微信小程序更换管理员
  10. vue中动态引入图片为什么要是require, 你不知道的那些事