D. Rocket Codeforces Round #499 (Div. 2)

D. Rocket

题目链接

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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≤x≤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≤y≤m). The correct answer to the question is −1−1, if x<yx<y, 00, if x=yx=y, and 11, if x>yx>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, ……, (n−1)(n−1)-th, nn-th, 11-st, 22-nd, 33-rd, ……, (n−1)(n−1)-th, nn-th, ……. 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).

Input

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

Interaction

You can ask the rocket no more than 6060 questions.

To ask a question, print a number yy (1≤y≤m1≤y≤m) and an end-of-line character, then do the operation flush and read the answer to the question.

If the program reads 00, then the distance is correct and you must immediately terminate the program (for example, by calling exit(0)). If you ignore this, you can get any verdict, since your program will continue to read from the closed input stream.

If at some point your program reads −2−2 as an answer, it must immediately end (for example, by calling exit(0)). You will receive the "Wrong answer" verdict, and this will mean that the request is incorrect or the number of requests exceeds 6060. If you ignore this, you can get any verdict, since your program will continue to read from the closed input stream.

If your program's request is not a valid integer between −231−231 and 231−1231−1 (inclusive) without leading zeros, then you can get any verdict.

You can get "Idleness limit exceeded" if you don't print anything or if you forget to flush the output.

To flush the output buffer you can use (after printing a query and end-of-line):

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

Hacking

Use the following format for hacking:

In the first line, print 33 integers m,n,xm,n,x (1≤x≤m≤1091≤x≤m≤109, 1≤n≤301≤n≤30) — the maximum distance to Mars, the number of elements in the sequence pp and the current distance to Mars.

In the second line, enter nn numbers, each of which is equal to 00 or 11 — sequence pp.

The hacked solution will not have access to the number xx and sequence pp.

题意:这是一道交互题,比赛的时候看见是交互题,而且读不懂题意就跳过了,赛后补题才发现是个傻逼题.....题意就是你要和一个傻子猜数,在1~m以内猜一个数,如果你猜小了,傻子就会返回1,猜大了则会返回-1,相等的话就会返回0,并结束程序。但是,这个傻子并不是每一次都会说实话,有时候会说谎,但是他说真话和谎话会有一个一个长度为n的周期。要求你询问傻子q次,根据傻子的回答,找出要猜的数。

思路:先不断的询问n次1,先查探出这个傻子的说实话和说谎的周期,如果回答为1,则说明本次回答为真话,因为不存在比1小的数了,如果回答为-1,则说明这次傻子的回答是谎话,如果回答为0,则大吉大利,找到结果了,直接结果程序。在得知傻子的回答真假周期p[]后,再真正的在1~m的区间进行二分查找即可。

#include<bits/stdc++.h>
using namespace std;
const int maxn=100+10;
int p[maxn];
int main() {
	int n,m,x;
	cin>>m>>n;
	for(int i=0; i<n; i++) {
		cout<<1<<endl;
		cin>>x;
		if(x==0) return 0;
		p[i]=x;
	}
	int l=1,r=m;
	for(int i=0; i<300; i++) {
		int mid=(l+r)>>1;
		cout<<mid<<endl;
		cin>>x;
		if(x==0) return 0;
		if(x*p[i%n]==1)
			l=mid+1;
		else
			r=mid;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40160605/article/details/81258823

相关文章