CF1010B.Rocket

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

This is an interactive problem.

Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet.

Let's define xx as the distance to Mars. Unfortunately, Natasha does not know xx. But it is known that 1≤x≤m1 \le x \le m, where Natasha knows the number mm. Besides, xx and mm are positive integers.

Natasha can ask the rocket questions. Every question is an integer yy (1≤y≤m1 \le y \le m). The correct answer to the question is −1-1, if x<yx \lt y, 00, if x=yx=y, and 11, if x>yx \gt y. But the rocket is broken — it does not always answer correctly. Precisely: let the correct answer to the current question be equal to tt, then, if the rocket answers this question correctly, then it will answer tt, otherwise it will answer −t-t.

In addition, the rocket has a sequence pp of length nn. Each element of the sequence is either 00 or 11. The rocket processes this sequence in the cyclic order, that is 11-st element, 22-nd, 33-rd, …\ldots, (n−1)(n-1)-th, nn-th, 11-st, 22-nd, 33-rd, …\ldots, (n−1)(n-1)-th, nn-th, …\ldots. If the current element is 11, the rocket answers correctly, if 00 — lies. Natasha doesn't know the sequence pp, but she knows its length — nn.

You can ask the rocket no more than 6060 questions.

Help Natasha find the distance to Mars. Assume, that the distance to Mars does not change while Natasha is asking questions.

Your solution will not be accepted, if it does not receive an answer 00 from the rocket (even if the distance to Mars is uniquely determined by the already received rocket's answers).

这是一个交互式问题。

娜塔莎即将飞往火星。终于,娜塔莎坐进了火箭。她飞啊飞……但感到无聊了。她希望快点抵达火星!于是她决定找点事情做来打发时间。她想不出比计算到这颗红色星球的距离更好的事情了。

我们定义 xx 为到火星的距离。不幸的是,娜塔莎并不知道 xx 的值。但已知 1≤x≤m1 \le x \le m,其中 mm 是娜塔莎已知的一个数。此外,xx 和 mm 均为正整数。

娜塔莎可以向火箭提问。每次提问是一个整数 yy(满足 1≤y≤m1 \le y \le m)。该问题的正确答案为:若 x<yx \lt y 则为 −1-1;若 x=yx = y 则为 00;若 x>yx \gt y 则为 11。但火箭坏了——它并不总是给出正确答案。具体来说:设当前问题的正确答案为 tt,那么如果火箭此次回答正确,则返回 tt;否则返回 −t-t。

此外,火箭内部有一个长度为 nn 的序列 pp。该序列的每个元素非 00 即 11。火箭按循环顺序处理该序列,即第 11 个、第 22 个、第 33 个、……、第 (n−1)(n-1) 个、第 nn 个、第 11 个、第 22 个、第 33 个、……、第 (n−1)(n-1) 个、第 nn 个、……依此类推。若当前处理的序列元素为 11,则火箭回答正确;若为 00,则说谎。娜塔莎不知道序列 pp 的具体内容,但她知道其长度 nn。

你最多可向火箭提出 6060 个问题。

请帮助娜塔莎确定到火星的距离。假设在娜塔莎提问过程中,到火星的距离 xx 保持不变。

若你的解法未从火箭处收到答案 00(即使根据已获得的所有火箭回答已能唯一确定火星距离),则该解法将不被接受。

输入格式

The first line contains two integers mm and nn (1≤m≤1091 \le m \le 10^9, 1≤n≤301 \le n \le 30) — the maximum distance to Mars and the number of elements in the sequence pp.

第一行包含两个整数 mm 和 nn(1≤m≤1091 \le m \le 10^9,1≤n≤301 \le n \le 30)—— 分别表示到火星的最大距离以及序列 pp 的元素个数。

输入输出样例

  • 输入#1

    5 2
    1
    -1
    -1
    1
    0

    输出#1

    1
    2
    4
    5
    3

说明/提示

In the example, hacking would look like this:

5 2 3

1 0

This means that the current distance to Mars is equal to 33, Natasha knows that it does not exceed 55, and the rocket answers in order: correctly, incorrectly, correctly, incorrectly ...

Really:

on the first query (11) the correct answer is 11, the rocket answered correctly: 11;

on the second query (22) the correct answer is 11, the rocket answered incorrectly: −1-1;

on the third query (44) the correct answer is −1-1, the rocket answered correctly: −1-1;

on the fourth query (55) the correct answer is −1-1, the rocket answered incorrectly: 11;

on the fifth query (33) the correct and incorrect answer is 00.

在示例中,黑客攻击过程如下:

5 2 3

1 0

这意味着当前到火星的距离为 33,娜塔莎知道该距离不超过 55,而火箭的回答顺序为:正确、错误、正确、错误……

实际情况如下:

  • 第一次查询(11):正确答案为 11,火箭回答正确:11;
  • 第二次查询(22):正确答案为 11,火箭回答错误:−1-1;
  • 第三次查询(44):正确答案为 −1-1,火箭回答正确:−1-1;
  • 第四次查询(55):正确答案为 −1-1,火箭回答错误:11;
  • 第五次查询(33):正确答案与错误答案均为 00。

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

首页