CF1438F.Olha and Igor

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an interactive problem.

Igor wants to find the key to Olha's heart. The problem is, that it's at the root of a binary tree.

There is a perfect binary tree of height hh consisting of n=2h−1n = 2^{h} - 1 nodes. The nodes have been assigned distinct labels from 11 to nn. However, Igor only knows hh and does not know which label corresponds to which node.

To find key to Olha's heart he needs to find the label assigned to the root by making queries of the following type at most n+420n+420 times:

  • Select three distinct labels uu, vv and ww (1≤u,v,w≤n1 \leq u,v,w \leq n).
  • In response, Olha (the grader) will tell him the label of the lowest common ancestor of nodes labelled uu and vv, if the tree was rooted at the node labelled ww instead.

Help Igor to find the root!

Note: the grader is not adaptive: the labels are fixed before any queries are made.

这是一个交互式问题。

伊戈尔想找到打开奥尔哈芳心的钥匙。问题是,这把钥匙位于一棵二叉树的根节点上。

存在一棵高度为 hh 的完美二叉树,共包含 n=2h−1n = 2^{h} - 1 个节点。这些节点被赋予了从 11 到 nn 的互不相同的标签。然而,伊戈尔只知道 hh,并不知道哪个标签对应哪个节点。

为了找到打开奥尔哈芳心的钥匙,他需要通过至多 n+420n+420 次如下类型的查询,确定根节点所对应的标签:

  • 选择三个互不相同的标签 uu、vv 和 ww(满足 1≤u,v,w≤n1 \leq u,v,w \leq n);
  • 作为回应,奥尔哈(评测程序)将告诉他:若将标签为 ww 的节点设为整棵树的根,则标签为 uu 和 vv 的两个节点的最低公共祖先(LCA) 所对应的标签。

请帮助伊戈尔找出根节点!

注意:评测程序是非自适应的,即所有节点的标签在任何查询发起前就已固定。

输入格式

The first and only line contains a single integer hh (3≤h≤183 \le h \le 18) — the height of the tree.

第一行且唯一一行包含一个整数 hh(3≤h≤183 \le h \le 18)——树的高度。

输入输出样例

  • 输入#1

    3
    
    2
    
    7
    
    4

    输出#1

    ? 7 3 5
    
    ? 1 6 4
    
    ? 1 5 4
    
    ! 4

说明/提示

The labels corresponding to the tree in the example are [44,77,22,66,11,55,33], meaning the root is labelled 44, and for 1<i≤n1 \lt i \le n, the parent of pip_i is p⌊i2⌋p_{ \lfloor{\frac{i}{2}}\rfloor }.

示例中树对应的标签为 [44,77,22,66,11,55,33],表示根节点的标签为 44,且对 1<i≤n1 \lt i \le n,节点 pip_i 的父节点为 p⌊i2⌋p_{ \lfloor{\frac{i}{2}}\rfloor }。

输入解题思路,AI测评打分。不知道怎么写?

首页