Codeforces Round #838 (Div. 2) D. GCD Queries
题意
有个长度为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进行两次询问,最多2n的限制内就可以筛选出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;
}
Codeforces Round #838 (Div. 2) D. GCD Queries的更多相关文章
- Codeforces Round #323 (Div. 2) C. GCD Table 暴力
C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C ...
- Codeforces Round #323 (Div. 2) C. GCD Table map
题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory l ...
- CodeForces Round #515 Div.3 C. Books Queries
http://codeforces.com/contest/1066/problem/C You have got a shelf and want to put some books on it. ...
- Codeforces Round #651 (Div. 2) B. GCD Compression(数论)
题目链接:https://codeforces.com/contest/1370/problem/B 题意 给出 $2n$ 个数,选出 $2n - 2$ 个数,使得它们的 $gcd > 1$ . ...
- Codeforces Round #767 (Div. 2)——B. GCD Arrays
B. GCD Arrays 题源:https://codeforces.com/contest/1629/problem/B 题目大意 给出一段区间[l, r],可以进行操作(把任意两个数拿出来,把他 ...
- Codeforces Round #323 (Div. 2) C.GCD Table
C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is define ...
- Codeforces Round #323 (Div. 1) A. GCD Table
A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Codeforces Round #323 (Div. 2) C GCD Table 582A (贪心)
对角线上的元素就是a[i],而且在所在行和列中最大, 首先可以确定的是最大的元素一定是a[i]之一,这让人想到到了排序. 经过排序后,每次选最大的数字,如果不是之前更大数字的gcd,那么只能是a[i] ...
- Codeforces Round #651 (Div. 2) B. GCD Compression (构造)
题意:有一个长度为\(2n\)的数组,删去两个元素,用剩下的元素每两两相加构造一个新数组,使得新数组所有元素的\(gcd\ne 1\).输出相加时两个数在原数组的位置. 题解:我们按照新数组所有元素均 ...
- Codeforces Round #582 (Div. 3) G. Path Queries (并查集计数)
题意:给你带边权的树,有\(m\)次询问,每次询问有多少点对\((u,v)\)之间简单路径上的最大边权不超过\(q_i\). 题解:真的想不到用最小生成树来写啊.... 我们对边权排序,然后再对询问的 ...
随机推荐
- 浏览器的 JavaScript 控制台功能调试vue
原始显示结果: 调试其中一个变量的值: 页面上呈现出调试后的效果了
- 不可错过的效能利器「GitHub 热点速览 v.22.39」
如果你是一名前端工程师且维护着多个网站,不妨试试本周榜上有名的 HTML-first 的 Qwik,提升网站访问速度只用一招.除了提升网站加载速度的 Qwik,本周周榜上榜的 Whisper 也是一个 ...
- [CG从零开始] 3. 安装 pyassimp 库加载模型文件
assimp 是一个开源的模型加载库,支持非常多的格式,还有许多语言的 binding,这里我们选用 assimp 的 python 的 binding 来加载模型文件.不过社区主要是在维护 assi ...
- C++面向对象编程之reference
1.声明 reference 一定要有初值,指针可以不用设初值 2. int& r = x; 表示 r 代表 x, r 用起来就是 x ,而且 reference 设完初值后再也不能代表其他变 ...
- 【SDOI2013】 项链 题解
Solution 将原问题分为两个问题求解. Part 1 首先求珍珠的种类数. 设\(f_i\)表示满足\(gcd = i\)的本质不同珍珠个数, \(g_i\)表示满足\(gcd\)为\(i\)的 ...
- 华为交换机VLAN常用命令
划分vlan vlan 10 划分Vlan10 vlan batch 30 40 同时创建vlan30和40 dispaly vlan 查看vlan信息 int e0/0/1 进入某一个接口 port ...
- 4.ElasticSearch系列之基本概念
1. 文档 ElasticSearch是面向文档的,文档是所有可搜索数据的最小单位 文档会被序列化成JSON格式,保存在ES中 每个文档都有一个unique ID #查看前10条文档,了解文档格式 P ...
- Conda的使用
conda常用的命令 在Anaconda Powershell Prompt 输入: 1.conda -V检验是否安装及当前conda的版本. 2.conda list查看安装了哪些包 3.conda ...
- 十五、资源控制之Deployment
资源控制器之Deployment Deployment 为 Pod 和 ReplicaSet 提供了一个声明式定义(declarative)方法,用来替代以前的ReplicationControlle ...
- QML 怎么调用 C++ 中的内容?
以下内容为本人的学习笔记,如需要转载,请声明原文链接微信公众号「englyf」https://mp.weixin.qq.com/s/z_JlmNe6cYldNf11Oad_JQ 先说明一下测试环境 编 ...