记录一下第一次写交互题

题目大意:一共有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(交互题)的更多相关文章

  1. Codeforces Round #371 (Div. 2) D. Searching Rectangles 交互题 二分

    D. Searching Rectangles 题目连接: http://codeforces.com/contest/714/problem/D Description Filya just lea ...

  2. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  3. Codeforces Round #575 (Div. 3) 昨天的div3 补题

    Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...

  4. 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 ...

  5. Codeforces Round #443 (Div. 1) C. Tournament

    题解: 思路挺简单 但这个set的应用好厉害啊.. 我们把它看成图,如果a存在一门比b大,那么a就可以打败b,a——>b连边 然后求强联通分量之后最后顶层的强联通分量就是能赢的 但是因为是要动态 ...

  6. Codeforces Round #812 (Div. 2) E(并查集)

    种类并查集:定义种类之间的关系来判断操作是否进行 题目大意:对于题目给出的一个矩阵,我们可以进行一种操作:swap(a[i][j],a[j][i]) 使得矩阵可以变换为字典序最小的矩阵 思路: 通过扫 ...

  7. 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 ...

  8. 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 ...

  9. Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

    A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...

随机推荐

  1. 获取进程产生了多少次pagefault

    怎么获取某个进程产生了多少次pagefault? 这个在ps 命令中可以看到,比如查看java的pagefault情况. ps -o maj_flt -o min_flt -p `ps -e|grep ...

  2. 【IDEA】IDEA怎么汉化&汉化后怎么转回英文

    ① 英文转中文 1.点击左上角的File,然后选择Setting 2.达到Setting页面选择Plugins 3.在搜索框搜索chinese,选择中文语言包下载 4.找到下载插件,选择勾选上,然后o ...

  3. zabbix_agentd断断续续端无法访问问题记录

    问题现象: zabbix监控上出现zabbix_agentd无法访问,但是实际上zabbix_agentd是存活状态 每隔一段时间就会出现这样的情况 问题原因 zabbix_agentd端任务较多,活 ...

  4. Linux 常用脚本命令

    Linux 常用(脚本)命令 1. 统计目录下文件个数 ll |grep "^-"|wc -1 解释 grep "^-"表示抓取以-开头的行(其他忽略)

  5. firewalld教程

    修改配置 cat firewalld.conf | grep -Ev "^#|^$" DefaultZone=trusted #主要是这个位置,必须修改trusted的 Minim ...

  6. Prometheus使用nginx 设置二级路径反向代理

    1.nginx 设置 location /promethues/ { proxy_pass http://10.xx.xxx.55:9090/prometheus/; } 2.设置prometheus ...

  7. nginx反向代理Grafana

    官方文旦地址:https://grafana.com/tutorials/run-grafana-behind-a-proxy/ 一级路径 只需要修改nginx配置文件 # this is requi ...

  8. CentOS obs直播RTMP协议推流到Nginx流媒体服务器到VUE使用HLS直播

    1. 发布打包前端管理平台(ant-design-vue) 2. 发布打包后端(.NET6-WebApi) .NET6 webAPI orm: free sql 数据库:mysql5.7 3. 发布打 ...

  9. .NET6 JWT(生成Token令牌)

    一.Net 6环境下的.net core项目里如何使用JWT. 第一步,在Nuget引入JWT.Microsoft.AspNetCore.Authentication.JwtBearer这两个NuGe ...

  10. echarts中setOption没有重新渲染表格

    setOption是merge,而非赋值,所以第二次setOption后,实际是更新了option setOption支持notMerge为true的方案,但是需要全量更新option(性能不好): ...