当前位置:网站首页>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.
边栏推荐
- 33. 分别谈谈联合索引生效和失效的条件
- mysql 5.7 入坑
- 力扣刷题记录2.1-----27. 移除元素
- Qt中QFile、QByteArray QDataStream和QTextStream区别
- Latex示例参考
- 2022护眼产品展,北京眼健康展,眼科医学展,近视矫正设备展
- 数字孪生+燃气管理,开启智慧燃气管理新模式
- 全文翻译:EDPB数据保护影响评估(DPIA:Data Protection Impact Assessment)指南
- 史上最猛“员工”,疯狂吐槽亿万富翁老板小扎:那么有钱,还总穿着同样的衣服!
- Data recovery software EasyRecovery supports recovery of all types of files
猜你喜欢

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

HNUMSC-C语言第一课

Using ngrok on Raspberry Pi (Extra 2)

VOIP使用单端口替换动态端口池进行UDP通信

typescript89-展示任务列表功能

力扣刷题记录1.5-----367. 有效的完全平方数

知识图谱学习笔记——我的第一次知识图谱实践

ROS2 ERROR: OpenGL 1.5 is not supported in GLRenderSystem::initialiseContext at C:\ci\ws\build...

2022PMP项目管理认证考试报考指南(1)

任务五 处理连续型数据
随机推荐
[C language brush questions] Application of fast and slow pointers in linked lists
力扣刷题记录1.5-----367. 有效的完全平方数
2022PMP项目管理认证考试报考指南(1)
力扣刷题记录9.1-----24. 两两交换链表中的节点
【Unity】判断鼠标是否点击在UI上
Grid布局介绍
MT4/MQL4入门到精通EA课程第二课-常用的功能函数
Latex示例参考
VOIP使用单端口替换动态端口池进行UDP通信
年金险的安全性怎么样啊?可靠吗?
企业里Foxmail邮箱问题解决方法汇总
2022杭电多校第五场1007(生成函数+启发式合并+ntt)
JDBC technology (3) - use Druid database connection pool test
全文翻译:EDPB数据保护影响评估(DPIA:Data Protection Impact Assessment)指南
Latex example reference
在树莓派上使用cpolar(番外篇2)
HCIP-R&S By Wakin自用笔记(3)OSPF之各类LSA及LSA更新规则
Cmake 报错 Could not find a package configuration file provided by “OpenCV“
torchversion.transforms的使用
程序员的日常生活 | 每日趣闻
