传送门
题目大意:
交互题,

n

(

4

n

1000

)

n(4\leq n\leq1000)

n(4≤n≤1000)个数字组成的数列

a

1

,

a

2

,

,

a

n

(

0

a

i

1

0

9

)

a_{1},a_{2},…,a_{n}(0\leq a_{i}\leq10^9)

a1​,a2​,…,an​(0≤ai​≤109),有且仅有

1

1

1个

0

0

0,每次询问

i

,

j

,

k

i,j,k

i,j,k,会给出

m

a

x

(

a

i

,

a

j

,

a

k

)

m

i

n

(

a

i

,

a

j

,

a

k

)

max(a_{i},a{j},a{k})-min(a_{i},a_{j},a_{k})

max(ai​,aj,ak)−min(ai​,aj​,ak​)的值,最多询问

2

n

2

2n-2

2n−2次,最后需要输出

i

,

j

i,j

i,j,使

a

i

,

a

j

a_{i},a_{j}

ai​,aj​当中有一个为

0

0

0。

思路:
题目可以转化为找出

n

2

n-2

n−2个绝对不会为

0

0

0的位置。我们考虑

4

4

4个数字

0

,

a

,

b

,

c

0,a,b,c

0,a,b,c,不妨设

0

<

a

b

c

0<a\leq b\leq c

0<a≤b≤c,那么在

4

4

4个数当中,我们记不选数字

a

a

a而选择了其他

3

3

3个数字询问而得到的答案记为

a

a'

a′,那么上面的例子中,

0

=

c

a

,

a

=

c

,

b

=

c

,

c

=

b

0'=c-a,a'=c,b'=c,c'=b

0′=c−a,a′=c,b′=c,c′=b,这

4

4

4个

a

n

s

ans

ans中最大的两个值所对应的位置一定不会为

0

0

0,因为如果为

0

0

0,那么舍弃掉既不是

0

0

0也不是这

4

4

4个当中最大值的两个位置中的一个去询问会得到的回答是这

4

4

4个数当中的最大值,一定比舍弃掉

0

0

0的询问更大,所以我们可以把

4

4

4个

a

n

s

ans

ans中最大的两个位置去掉,这样通过每轮

4

4

4个询问我们可以排除掉两个位置,(

4

4

4位置都没有

0

0

0的情况下也可以这样算,都不是

0

0

0去掉两个显然没有问题)当

n

n

n为偶数时,我们只需要询问

n

2

2

4

=

2

n

4

\frac{n-2}{2}*4=2n-4

2n−2​∗4=2n−4次,而如果为奇数,最后会剩余

3

3

3个没有去掉的位置,我们只需要把之前任意一个去掉过的位置拿过来凑够

4

4

4个再进行

1

1

1轮即可,总的询问次数时

n

3

2

4

+

4

=

2

n

2

\frac{n-3}{2}*4+4=2n-2

2n−3​∗4+4=2n−2,都可以满足要求。

代码:

#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
//#define int LL
//#define endl '\n'
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#pragma warning(disable :4996)
const double eps = 1e-8;
const LL mod = 1000000007;
const LL MOD = 998244353;
const int maxn = 1010; int T, N;
bool used[maxn]; void solve()
{
PII res[4];
vector<int>num;
int lst = N, pos = 1, tmp, ans;
while (lst > 3)
{
while (num.size() < 4)
{
if (!used[pos])
num.push_back(pos);
pos++;
}
for (int i = 0; i < 4; i++)
{
cout << "? " << num[i] << ' ' << num[(i + 1) % 4] << ' ' << num[(i + 2) % 4] << endl;
cin >> ans;
res[i] = PII(ans, num[(i + 3) % 4]);
}
sort(res, res + 4);
int a = res[2].second, b = res[3].second;
used[a] = used[b] = true;
num.erase(find(num.begin(), num.end(), a)), num.erase(find(num.begin(), num.end(), b));
tmp = a;
lst -= 2;
}
if (lst == 2)
cout << "! " << num[0] << ' ' << num[1] << endl;
else
{
while (num.size() < 3)
{
if (!used[pos])
num.push_back(pos);
pos++;
}
num.push_back(tmp);
for (int i = 0; i < 4; i++)
{
cout << "? " << num[i] << ' ' << num[(i + 1) % 4] << ' ' << num[(i + 2) % 4] << endl;
cin >> ans;
res[i] = PII(ans, num[(i + 3) % 4]);
}
sort(res, res + 4);
int a = res[2].second, b = res[3].second;
used[a] = used[b] = true;
num.erase(find(num.begin(), num.end(), a)), num.erase(find(num.begin(), num.end(), b));
cout << "! " << num[0] << ' ' << num[1] << endl;
}
} int main()
{
IOS;
cin >> T;
while (T--)
{
cin >> N;
memset(used, false, sizeof(used));
solve();
} return 0;
}

Codeforces Round #770 (Div. 2)D的更多相关文章

  1. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  7. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. 003Linux查看文件内容的5个命令姿势

    01 开篇 Linux 中查看文件内容常用的有如下 5 个命令: cat: more: less: tail: head. 02依次看看这些命令的使用姿势 cat 一次性将所有内容输出到屏幕上,方便查 ...

  2. Iptables的命令与用法

    目录 一:iptables的用法 1.iptables简介 二:Iptables链的概念 1.那四个表,有哪些作用? 2.那五条链,运行在那些地方? 3.Iptables流程图 三:iptables的 ...

  3. jsp 中的绝对路径和相对路径 ./ 和 ../的区别?

    原文地址! https://www.cnblogs.com/brucetie/p/4109913.html 1. 相对路径 相对路径,当前的文件,以根目录为基准,相对于另一个文件的位置. 2.绝对路径 ...

  4. 【Python爬虫】爬虫利器 requests 库小结

    requests库 Requests 是一个 Python 的 HTTP 客户端库. 支持许多 HTTP 特性,可以非常方便地进行网页请求.网页分析和处理网页资源,拥有许多强大的功能. 本文主要介绍 ...

  5. ApacheCN PHP 译文集 20211101 更新

    PHP 入门指南 零.序言 一.PHP 入门 二.数组和循环 三.函数和类 四.数据操作 五.构建 PHP Web 应用 六.搭建 PHP 框架 七.认证与用户管理 八.建立联系人管理系统 使用 PH ...

  6. Swift数组

    数组的介绍 数组(Array)是一串有序的由相同类型元素构成的集合 数组中的集合元素是有序的,可以重复出现 Swift中的数组 swift数组类型是Array,是一个泛型集合 数组的初始化 数组分成: ...

  7. 长时间不操作Navicat或Putty会断线?

    问题描述 今天发现只要一直不使用Putty,发现就会"卡住",还有Navicat连接数据库也有类似问题. 问题分析 Linux或者数据库都想节省连接资源呗. 问题解决 那就隔一段时 ...

  8. Nodejs ORM框架Sequelize快速入门

    Nodejs ORM框架Sequelize快速入门 什么是ORM? 简单的讲就是对SQL查询语句的封装,让我们可以用OOP的方式操作数据库,优雅的生成安全.可维护的SQL代码.直观上,是一种Model ...

  9. java代码注意点总结(持续更新)

    1. if(username.equals("zxx")){} 这样写的话,如果username是null, 则会报NullPointerException,所以先要判断usern ...

  10. 【职业规划】该如何选择职业方向?性能?自动化?测开?,学习选择python、java?看完你会感谢我的~

    前言 随着近两年来互联网行业的飞速发展,互联网技术的从业人员也越来越多. 近两年来技术岗位中测试和前端工程师变成了程序员中最好招的岗位. 测试行业卷也越来越厉害了. 也正是因为如此,我们要把自己的路越 ...