CF1470C.Strange Shuffle

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

This is an interactive problem.

nn people sitting in a circle are trying to shuffle a deck of cards. The players are numbered from 11 to nn , so that players ii and i+1i+1 are neighbours (as well as players 11 and nn ). Each of them has exactly kk cards, where kk is even. The left neighbour of a player ii is player i1i - 1 , and their right neighbour is player i+1i + 1 (except for players 11 and nn , who are respective neighbours of each other).

Each turn the following happens: if a player has xx cards, they give x/2\lfloor x / 2 \rfloor to their neighbour on the left and x/2\lceil x / 2 \rceil cards to their neighbour on the right. This happens for all players simultaneously.

However, one player pp is the impostor and they just give all their cards to their neighbour on the right. You know the number of players nn and the number of cards kk each player has initially, but pp is unknown to you. Your task is to determine the value of pp , by asking questions like "how many cards does player qq have?" for an index qq of your choice. After each question all players will make exactly one move and give their cards to their neighbours. You need to find the impostor by asking no more than 10001000 questions.

输入格式

The first line contains two integers nn and kk ( 4n1054 \le n \le 10^5 , 2k1092 \le k \le 10^9 , kk is even) — the number of players and the number of cards.

输出格式

You can ask questions by printing "? qq ". The answer to this question is the number of cards player qq has now ( 1qn1 \le q \le n ). The shuffling process starts immediately after your first question, so the answer to the first one is always equal to kk .

Once you have identified the impostor, you can output the answer by printing "! pp ", where pp is the player who is the impostor ( 1pn1 \le p \le n ). Then you have to terminate your program.

You have to find the impostor by asking no more than 10001000 questions.

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see documentation for other languages.

Hacks

To make a hack, use the following test format.

The only line of input should contain three integers nn , kk and pp ( 4n1054 \le n \le 10^5 , 2k1092 \le k \le 10^9 , kk is even, 1pn1 \le p \le n ) — the number of people, the number of cards each person has initially, and the position of the impostor.

输入输出样例

  • 输入#1

    4 2
    
    2
    
    1
    
    2
    
    3
    
    2

    输出#1

    ? 1
    
    ? 1
    
    ? 2
    
    ? 3
    
    ? 4
    
    ! 2

说明/提示

In the example the cards are transferred in the following way:

  • 22 22 22 22 — player 11 has 22 cards.
  • 11 22 33 22 — player 11 has 11 card.

After this turn the number of cards remains unchanged for each player.

首页