Codeforces Round #720 (Div. 2)题解

本文详细解析了Codeforces Round #720 中的两道题目,包括C题"Nastia and a Hidden Permutation"的交互策略和D题"Nastia Plays with a Tree"的DFS与贪心解法。通过互动模型求解隐藏的排列,并在树形结构中寻找最小操作次数,转变为链状结构。
摘要由CSDN通过智能技术生成

C.Nastia and a Hidden Permutation

题目:
This is an interactive problem!

Nastia has a hidden permutation p of length n consisting of integers from 1 to n n n. You, for some reason, want to figure out the permutation. To do that, you can give her an integer t ( 1 ≤ t ≤ 2 ) t( 1\le t\le 2) t(1t2), two different indices i i i and j ( 1 ≤ i , j ≤ n , i ≠ j ) j(1\le i,j\le n,i\ne j) j(1i,jn,i=j), and an integer x ( 1 ≤ x ≤ n − 1 ) x(1\le x\le n-1) x(1xn1)

Depending on t t t, she will answer:
t = 1 : m a x ( m i n ( x , p i ) , m i n ( x + 1 , p j ) ) t = 2 : m i n ( m a x ( x , p i ) , m a x ( x + 1 , p j ) ) t=1:max(min(x,p_i),min(x+1,p_j))\\t=2:min(max(x,p_i),max(x+1,p_j)) t=1:max(min(x,pi),min(x+1,pj))t=2:min(max(x,pi),max(x+1,pj))
You can ask Nastia at most ⌊3⋅n/2⌋+30 times. It is guaranteed that she will not change her permutation depending on your queries. Can you guess the permutation?

题意:
交互题:给一个1到 n n n的序列,通过最多 ⌊ 3 ∗ n 2 ⌋ + 30 − n + 1 \lfloor \frac{3*n}{2} \rfloor+30-n+1 23n+30n+1次操作,最终猜出这 n n n个数分别是什么。
对于每次操作需给出操作方法序号,猜测值 x x x,以及猜测数下标 i , j i,j ij
①返回 m a x ( m i n ( x , p i ) , m i n ( x + 1 , p j ) ) max(min(x,p_i),min(x+1,p_j)) max(min(x,

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值