Codeforces Round #812 (Div. 2) D. Tournament Countdown(交互题)
记录一下第一次写交互题
题目大意:一共有1<<n个人参加一场竞标赛,需要你通过比较两人的胜场来判断谁晋级,最终获得第一名
最多1/3*2^(n+1)次询问,每次询问query(a,b),如果a胜场多返回1,如果b胜场多返回2,相同胜场返回0
找到冠军后输出“! i”(i为冠军的编号)
思路:
每次取四个人一组,因为如果这一组人进行了t轮比赛后,最终有一人胜出,那么他们的胜场将为
[ t , t , t+1 , t+2 ],而且 t 和 t 不能出现在同一组,那么他们的胜场排列基本如下[ t , t+1 t , t+2 ]
所以先对奇数进行查询(query(a[i],a[i+2])),如果相同(t==0),说明他们俩同时被淘汰,此时只用比较偶数组,谁多谁胜出
否则如果不同,若返回1,说明a[i]为t+1或者t+2,这时只用比较a[i]与a[i+3]即可
同理返回2
1 # include<iostream>
2 # include<bits/stdc++.h>
3 using namespace std;
4 # define int long long
5
6 int ask(int a, int b) {
7 cout << "? " << a << ' ' << b << endl;
8 int t;
9 cin >> t;
10 return t;
11 }
12 int tt;
13 signed main() {
14 ios::sync_with_stdio(0);
15 cin.tie(0);
16 cout.tie(0);
17 cin >> tt;
18 while (tt--) {
19 int n;
20 cin >> n;
21 vector<int> a;
22 n = 1 << n;
23 for (int i = 1; i <= n; ++i) {
24 a.push_back(i);
25 }
26 while (n >= 4) {
27 vector<int> b;
28 for (int i = 0; i < n; i += 4) {
29 int t = ask(a[i], a[i + 2]);
30 if (t == 0) {
31 int t2 = ask(a[i + 1], a[i + 3]);
32 if (t2 == 1) b.push_back(a[i + 1]);
33 else b.push_back(a[i + 3]);
34 } else if (t == 1) {
35 int t2 = ask(a[i], a[i + 3]);
36 if (t2 == 1) b.push_back(a[i]);
37 else b.push_back(a[i + 3]);
38 } else {
39 int t2 = ask(a[i + 1], a[i + 2]);
40 if (t2 == 1) b.push_back(a[i + 1]);
41 else b.push_back(a[i + 2]);
42 }
43 }
44 n /= 4;
45 a.swap(b);
46 }
47 if (a.size() == 2) {
48 int t = ask(a[0], a[1]);
49 if (t == 1) cout << '!' << ' ' << a[0] << endl;
50 else cout << '!' << ' ' << a[1] << endl;
51 } else cout << '!' << ' ' << a[0] << endl;
52
53 }
54
55
56 return 0;
57 }
Codeforces Round #812 (Div. 2) D. Tournament Countdown(交互题)的更多相关文章
- Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分
D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #443 (Div. 1) C. Tournament
题解: 思路挺简单 但这个set的应用好厉害啊.. 我们把它看成图,如果a存在一门比b大,那么a就可以打败b,a——>b连边 然后求强联通分量之后最后顶层的强联通分量就是能赢的 但是因为是要动态 ...
- Codeforces Round #812 (Div. 2) E(并查集)
种类并查集:定义种类之间的关系来判断操作是否进行 题目大意:对于题目给出的一个矩阵,我们可以进行一种操作:swap(a[i][j],a[j][i]) 使得矩阵可以变换为字典序最小的矩阵 思路: 通过扫 ...
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
- Codeforces Round #303 (Div. 2) A. Toy Cars 水题
A. Toy Cars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/problem ...
- Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...
随机推荐
- 【Java】学习路径53-InetAdress获取服务器ip
InetAdress如何使用? import java.net.*; public class InetAdress { public static void main(String[] args) ...
- 实时降噪(Real-time Denoising):Spatio-Temporal Filtering
目录 空间滤波(Spatial Filtering) 基于距离的高斯滤波 双边滤波(Bilateral filtering) 联合双边滤波(Joint Bilateral filtering)[201 ...
- 第九十六篇:恶补JS基础
好家伙,来补基础啦,补JS的基础 先来一些概念性的东西 1.什么是JavaScript? javaScript的简写形式就是JS,一种广泛用于客户端Web开发的脚本语言,常用来给HTML网页添加动态 ...
- 第三课:nodejs npm和vue
1.安装node js 2.node js给windows提供了一个可以直接执行js的环境{node提供翻译} 3.npm是包管理器 a.npm是nodejs的组成部分 b.管 包(package) ...
- KingbaseESV8R6 垃圾回收原理以及如何预防膨胀
背景 KingbaseESV8R6支持snapshot too old 那么实际工作中,经常看到表又膨胀了,那么我们讨论一下导致对象膨胀的常见原因有哪些呢? 未开启autovacuum 对于未开启au ...
- 使用plsql_plprofiler 分析过程块的执行
前言:存储过程可能涉及很多的SQL及控制块,我们看到的执行时间是整个过程块的执行时间,如果我们认为性能有问题,我们只能逐条SQL的分析,查找问题SQL,效率非常低下.KingbaseES 提供了 pl ...
- EntityFrameworkCore 模型自动更新(上)
话题 嗯,距离上一次写博文已经过去近整整十个月,还是有一些思考,但还是变得懒惰了,心思也不再那么专注,有点耗费时间,学习也有点停滞不前,那就顺其自然,随心所欲吧,等哪天心血来潮,想写了就写写 模型自动 ...
- JavaScript 闭包 —— { }
闭包是什么 闭包是一个[函数](一个作用域可以访问另一个函数的局部变量) 闭包的作用 延伸变量的作用域 function f() { let num = 21; return function () ...
- Unity2D-Dash && SpeedUp
Introduction 原理: 角色位置改变时,每隔一段时间记录角色的位置,然后在记录的位置上放置一个图片,在图片出现之后过一段时间就让图片渐渐消失 简述实现步骤: 1.在Unity中Creat ...
- 论文解读(RvNN)《Rumor Detection on Twitter with Tree-structured Recursive Neural Networks》
论文信息 论文标题:Rumor Detection on Twitter with Tree-structured Recursive Neural Networks论文作者:Jing Ma, Wei ...