当前位置:网站首页>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.
边栏推荐
- JDBC technology (3) - use Druid database connection pool test
- JDBC技术(三)——使用Druid数据库连接池测试
- 数据恢复软件EasyRecovery支持恢复所有类型的文件
- class path resource [bean.xml] cannot be opened because it does not 错误解决方案
- [C language brush questions] Application of fast and slow pointers in linked lists
- 方法参数
- 保护您的 Web 应用程序的最佳开源 Web 应用程序防火墙
- [Signal denoising] Based on Sage-Husa adaptive Kalman filter to realize the suppression of ocean wave magnetic field noise and the generation of ocean wave magnetic field noise with matlab code
- 论文笔记:SAITS: SELF-ATTENTION-BASED IMPUTATION FOR TIMESERIES
- 《LC刷题总结》—— 二叉树
猜你喜欢
如何在群晖系统中安装cpolar(群晖6.X版)
425 Can‘t open data connection for transfer of “/“
线段树知识整理
LeetCode每日一题:搜索插入位置 (均1200道)方法:二分查找
The Best Open Source Web Application Firewall to Protect Your Web Applications
数字孪生+燃气管理,开启智慧燃气管理新模式
虹科技术|如何阻止供应链攻击?
Educational Codeforces Round 132 (Rated for Div. 2)
日文翻译-在线免费日文翻译软件
How SEMRush finds keywords for advertising
随机推荐
Use of torchversion.transforms
配置文件的读取-TOML
SEMRush如何寻找关键词用于投放广告
【Fiddler】Fiddler实现mock测试(模拟接口数据)
全文翻译:欧盟第29条数据保护工作组 数据保护官指南
[机缘参悟-65]:《兵者,诡道也》-6-孙子兵法解读-并战计
final
JDBC technology (2) - set up common sql and configuration files
使用JS实现数组扁平化的几种方式
JDBC technology (3) - use Druid database connection pool test
Image denoising based on edge enhancement Diffusion 】 (cEED) and Coherence Enhancing coursing together (cCED) filter to realize image denoising matlab code
右键新建缺少word、excel选项问题处理
进程和线程
D. Tournament Countdown
力扣刷题记录3.1-----977. 有序数组的平方
谷歌翻译软件-免费谷歌翻译
mysql 5.7 入坑
TP测试查询数据库字段为null或空的字段
线段树知识整理
2022中国眼博会,中国北京国际儿童青少年眼睛健康产业展览会