题目描述

Michael and Brian are stuck in a hotel with $ n $ rooms, numbered from $ 1 $ to $ n $ , and need to find each other. But this hotel's doors are all locked and the only way of getting around is by using the teleporters in each room. Room $ i $ has a teleporter that will take you to room $ a_i $ (it might be that $ a_i = i $ ). But they don't know the values of $ a_1,a_2, \dots, a_n $ .

Instead, they can call up the front desk to ask queries. In one query, they give a room $ u $ , a positive integer $ k $ , and a set of rooms $ S $ . The hotel concierge answers whether a person starting in room $ u $ , and using the teleporters $ k $ times, ends up in a room in $ S $ .

Brian is in room $ 1 $ . Michael wants to know the set $ A $ of rooms so that if he starts in one of those rooms they can use the teleporters to meet up. He can ask at most $ 2000 $ queries.

The values $ a_1, a_2, \dots, a_n $ are fixed before the start of the interaction and do not depend on your queries. In other words, the interactor is not adaptive.

$ 2 \leq n \leq 500 $

当你已经知道了 \(1\) 所在的环之后,就很好判断一个点和在一个连通块了。判断一下这个点走 \(n\) 步之后是否在那个环就行了。

我们可以用二分求出一个 \(a_x\).

可以先用 \(1\) 走 \(n\) 步得到环上的某一个点 \(x\),如何扩展出整个环。首先可以一个个求 \(a_x\),那么大概是 \(9n\) 的时间,不行。

考虑倍增。假设我们现在得到了环上的 \(c\) 个点,那么我们可以通过询问一个点走 \(c\) 步是否在环上,这样可以在 \(O(n)\) 的次数内求出 \(c\) 个环上的点。

考虑把上面两种方式结合起来,先用第一种方法求出 \(64\) 个点,然后用第二种方法倍增出剩下的就行了。

细节很多。

#include<bits/stdc++.h>
using namespace std;
const int N=505;
int n,x,a[N],v[N],p[31][N],k,q[N],fa[N],m=1,cnt=0;
mt19937 gen(time(0));
int find(int x)
{
if(fa[x]==x)
return x;
return fa[x]=find(fa[x]);
}
int ok()
{
int c=0;
for(int i=1;i<=n;i++)
fa[i]=i;
for(int i=1;i<=n;i++)
fa[find(p[0][i])]=find(i);
for(int i=1;i<=n;i++)
if(find(i)==find(1))
++c;
if(c^m)
return 0;
for(int i=1;i<=m;i++)
if(find(a[i])^find(1))
return 0;
return 1;
}
void maker()
{
for(int i=1;i<=n;i++)
{
p[0][i]=gen()%n+1;
//printf("%d ",p[0][i]);
}
for(int j=1;j<=30;j++)
for(int k=1;k<=n;k++)
p[j][k]=p[j-1][p[j-1][k]];
}
/*int qry(int x,int k,int m)
{
++cnt;
int px=x;
if(x>n||x<1)
{
puts("Wrong query");
return 0;
}
for(int i=30;~i;--i)
if(k>>i&1)
x=p[i][x];
for(int i=1;i<=m;i++)
if(q[i]==x)
return 1;
return 0;
}*/
int ask(int u,int k)
{
int l=1,r=n;
while(l<r)
{
int md=l+r>>1;
printf("? %d %d %d ",u,k,md-l+1);
for(int i=l;i<=md;i++)
printf("%d ",i);
puts("");
fflush(stdout);
scanf("%d",&x);
/*for(int i=l;i<=md;i++)
q[i-l+1]=i;
x=qry(u,k,md-l+1);*/
if(x)
r=md;
else
l=md+1;
}
return l;
}
int main()
{
scanf("%d",&n);
maker();
a[1]=ask(1,1000000000);
v[a[1]]=1;
for(int i=1;i>=0&&i<=n;i<<=1)
{
int pm=m;
if(i*9<n)
{
for(int j=1;j<=i;j++)
{
a[m+1]=ask(a[m],1),++m;
if(v[a[m]])
j=i,i=-1,--m;
else
v[a[m]]=1;
}
}
else
{
for(int j=1;j<=n;j++)
{
if(v[j])
continue;
printf("? %d %d %d ",j,i,m);
for(int k=1;k<=m;k++)
printf("%d ",a[k]);
puts("");
fflush(stdout);
scanf("%d",&x);
/*for(int k=1;k<=i;k++)
q[k]=a[k];
x=qry(j,i,i);*/
if(x)
v[a[++m]=j]=1;
}
}
if(m==pm)
break;
if(2*i>m)
break;
}
q[1]=a[1];
for(int i=1;i<=n;i++)
{
if(!v[i])
{
printf("? %d 1000000000 %d ",i,m);
for(int j=1;j<=m;j++)
printf("%d ",a[j]);
puts("");
fflush(stdout);
scanf("%d",&x);
/*for(int j=1;j<=m;j++)
q[j]=a[j];
x=qry(i,1000000000,m);*/
if(x)
a[++m]=i;
}
}
printf("! %d ",m);
for(int i=1;i<=m;i++)
printf("%d ",a[i]);
fflush(stdout);
/*if(ok())
printf("succes,%d\n",cnt);
else
puts("failed");*/
return 0;
}

[CF1854D] Michael and Hotel的更多相关文章

  1. [ZZ] A Proposal For Compiling Direct3D HLSL With LLVM (Written by Michael Larabel )

    http://www.phoronix.com/scan.php?page=news_item&px=OTI2NA Note:  Something very instersting to w ...

  2. Michael Schatz - 序列比对课程

    Michael Schatz - Cold Spring Harbor Laboratory 最近在研究 BWA mem 序列比对算法,直接去看论文,看不懂,论文就3页,太精简了,好多背景知识都不了解 ...

  3. POJ 3667 Hotel(线段树 区间合并)

    Hotel 转载自:http://www.cnblogs.com/scau20110726/archive/2013/05/07/3065418.html [题目链接]Hotel [题目类型]线段树 ...

  4. ACM: Hotel 解题报告 - 线段树-区间合并

    Hotel Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Description The ...

  5. HDU - Hotel

    Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...

  6. 【POJ3667】Hotel

    Description The cows are journeying north to Thunder Bay in Canada to gain cultural enrichment and e ...

  7. POJ-2726-Holiday Hotel

    Holiday Hotel   Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8302   Accepted: 3249 D ...

  8. Method threw 'org.hibernate.exception.SQLGrammarException' exception. Cannot evaluate com.hotel.Object_$$_jvst485_15.toString()

    数据库字段和类Object属性不匹配,Method threw 'org.hibernate.exception.SQLGrammarException' exception. Cannot eval ...

  9. poj 3667 Hotel(线段树,区间合并)

    Hotel Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 10858Accepted: 4691 Description The ...

  10. [听课笔记]Professor Michael Cusumano's New Book:" Strategy Rules: Five Timeless Lessons from Bill Gates, Andy Grove, and Steve Jobs"

    1. Look Forward, Reason Back Extrapolate, interpret, then tie vision to concrete actions2. Make Big ...

随机推荐

  1. ChatGPT赋能低代码开发:打造智能应用的双重引擎

    摘要:本文摘自葡萄城低代码产品活字格的资深用户(格友超哥)所撰写的文章:<惊叹表现!活字格+ChatGPT:低代码开发智能应用的巨大潜力>. ChatGPT的functions函数使用方 ...

  2. 原神盲盒风格:AI绘画Stable Diffusion原神人物公仔实操:核心tag+lora模型汇总

    本教程收集于:AIGC从入门到精通教程汇总 在这篇文章中,我们将深入探讨原神盲盒的艺术风格,以及如何运用AI绘画技术(Stable Diffusion)--来创造原神角色公仔.我们将通过实践操作让读者 ...

  3. ctypes使用浅谈

    什么是ctypes: ctypes 是 Python 的一个标准库,用于与 C 语言进行交互.它提供了一组工具和函数,可以方便地调用动态链接库(DLL)或共享对象(SO)中的 C 函数,并处理 C 数 ...

  4. mall :hutool项目源码解析

    目录 一.mall开源项目 1.1 来源 1.2 项目转移 1.3 项目克隆 二.Hutool工具类库 2.1 Hutool 简介 三.源码解析 3.1 集成与配置 3.1.1 导入依赖 3.1.2 ...

  5. KRPANO PR10最新激活码(破解)分享

    KRPano pr10最新版本激活码下载地址: http://pan.baidu.com/s/1qYv2vO4 适用于最新pr10以及之前版本,解压密码为KRPano技术解密群群号:551278936 ...

  6. 618京东到家APP-门详页反爬实战

    一.背景与系统安全需求分析 1. 系统的重要性 上图所示是接口所属位置.对电商平台或在线商店而言,分类查商品都是很重要的,通过为用户提供清晰的商品分类,帮助他们快速找到所需产品,节省浏览时间,提升购物 ...

  7. SpringBoot + Redis + Token 解决接口幂等性问题

    前言 SpringBoot实现接口幂等性的方案有很多,其中最常用的一种就是 token + redis 方式来实现. 下面我就通过一个案例代码,帮大家理解这种实现逻辑. 原理 前端获取服务端getTo ...

  8. 织梦DedeCMS文章内容页调用标签方法教程

    织梦DedeCMS是新手站长使用比较多的建站软件,其模板制作也比较方便,一些站长朋友对其模板调用标签不是太熟悉,小编为大家介绍下织梦文章内容页调用标签的方法. 1.调用文章标题: {dede:fiel ...

  9. MySQL实战实战系列 06 全局锁和表锁 :给表加个字段怎么有这么多阻碍?

    今天我要跟你聊聊 MySQL 的锁.数据库锁设计的初衷是处理并发问题.作为多用户共享的资源,当出现并发访问的时候,数据库需要合理地控制资源的访问规则.而锁就是用来实现这些访问规则的重要数据结构. 根据 ...

  10. Xshell远程连接、MBR/BOOT和GRUB三者关系总结(系统启动过程)

    远程连接 远程连接Linux服务器的常见工具有Xshell.SecureCRT.Putty等,这些客户端连接工具在Linux服务器对应着相同SSH服务进程sshd,即远程连接都是使用SSH协议,当然它 ...