当前位置:网站首页>D. Tournament Countdown
D. Tournament Countdown
2022-08-09 02:03:00 【beyond+myself】
题意:
1:交互题
2:给出n
3:共有2 ^ n个队员
4:? a b means to ask the systema,bWhoever wins the most games(i.e. who is at a higher level in the graph)
5:The final result is expressed as ! res
6:The maximum number of inquiries is (2/3)*(2^(n+1) ) 上取整
题解:我们可以计算一下,If we ask two by two,The final number of inquiries is2^(n+1)-1is higher than the limit of the number of questions,Then we started thinking about reducing the number of inquiries.
We tried four one inquiries,我们以 1,2,3,4为例:两个一组,Suppose we compare1,3,when the two are equal,They must be at the lowest level;但是如果1>3的话,可能1,3all on the second floor,In this case it is not feasible if we still expect to determine the number of second layers,This way the number of inquiries is still in the worst case2^(n+1)的,So we directly determine the third layer here(That is, two floors up),这种情况下,We can determine the number of the upper two floors by asking twice at most.We can count the number of queries,Originally, it took three times to determine the numbers for the two floors,Now just ask twice,这样就是(2/3 * 2 ^ (n+1))Exactly meet the limit in the question.
下面是AC代码:
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
vector<int> vec;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,num=1;
cin>>n;
vec.clear();
for(int i=1;i<=n;i++) num*=2;
for(int i=1;i<=num;i++) vec.push_back(i);
if(num>=4)
{
while(vec.size()>2)
{
int len=vec.size();
for(int i=0;i<len;i+=4)
{
cout<<"?"<<" "<<vec[i]<<" "<<vec[i+2]<<endl;
//cout.flush();
int x;
cin>>x;
if(x==1)
{
cout<<"?"<<" "<<vec[i]<<" "<<vec[i+3]<<endl;
//cout.flush();
int x;
cin>>x;
if(x==1) vec.push_back(vec[i]);
else if(x==2) vec.push_back(vec[i+3]);
}
else if(x==2)
{
cout<<"?"<<" "<<vec[i+1]<<" "<<vec[i+2]<<endl;
//cout.flush();
int x;
cin>>x;
if(x==1) vec.push_back(vec[i+1]);
else if(x==2) vec.push_back(vec[i+2]);
}
else if(x==0)
{
cout<<"?"<<" "<<vec[i+1]<<" "<<vec[i+3]<<endl;
//cout.flush();
int x;
cin>>x;
if(x==1) vec.push_back(vec[i+1]);
else if(x==2) vec.push_back(vec[i+3]);
}
}
vec.erase(vec.begin(),vec.begin()+len);
}
}
cout<<"?"<<" "<<vec[0]<<" "<<vec[1]<<endl;
//cout.flush();
int x;
cin>>x;
if(x==1) cout<<"!"<<" "<<vec[0]<<endl;
else cout<<"!"<<" "<<vec[1]<<endl;
}
return 0;
}
This question requires addingcout.flush()的,But not right.
边栏推荐
- 程序员的日常生活 | 每日趣闻
- final
- ffplay playback control
- The server quit without updating PID file (/usr/local/mysql/data/localhost.pid).
- 考研人总结的时间管理7大忌,你中了几条?
- 全文翻译:欧盟第29条数据保护工作组 数据保护官指南
- 2022 PMP Project Management Certification Exam Registration Guide (1)
- Go-8-Gin框架
- 力扣刷题记录5.1-----59. 螺旋矩阵 II
- LeetCode每日两题02:轮转数组 (均1200道)
猜你喜欢

torchversion.transforms的使用

The 7 taboos of time management summarized by the postgraduate students, how many have you won?

typescript90-使用类型文件声明类型

解决有路由策略的情况下域内NAT不通的问题

TCP/IP协议栈

力扣刷题记录9.1-----24. 两两交换链表中的节点
![[C language brush questions] Application of fast and slow pointers in linked lists](/img/de/907192f705d9b2dc1628d480c4d7d9.png)
[C language brush questions] Application of fast and slow pointers in linked lists

《LC刷题总结》—— 二叉树

力扣刷题记录3.1-----977. 有序数组的平方

Grid布局介绍
随机推荐
mysql 5.7 入坑
考研人总结的时间管理7大忌,你中了几条?
[深入研究4G/5G/6G专题-55]: L3信令控制-4-软件功能与流程的切分-CU网元的信令
HCIP-R&S By Wakin自用笔记(3)OSPF之各类LSA及LSA更新规则
MT4/MQL4入门到精通外汇EA教程第一课 认识MetaEditor
JDBC技术(二)——设置通用的sql和配置文件
使用百度EasyDL实现智能垃圾箱
The 7 taboos of time management summarized by the postgraduate students, how many have you won?
软件测试技术之如何编写测试用例(5)
2022杭电多校第五场1007(生成函数+启发式合并+ntt)
2022护眼产品展,北京眼健康展,眼科医学展,近视矫正设备展
《LC刷题总结》——贪心
Go-12-Structure
LVGL简介(基于v8.1-8.2)
史上最猛“员工”,疯狂吐槽亿万富翁老板小扎:那么有钱,还总穿着同样的衣服!
日文翻译-在线免费日文翻译软件
软件开发之我的一点想法
德语翻译器在线翻译中文
The server quit without updating PID file (/usr/local/mysql/data/localhost.pid).
深度学习模型的两种部署:ONNX与Caffe
