博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #499 (Div. 2) D. Rocket题解
阅读量:5231 次
发布时间:2019-06-14

本文共 5222 字,大约阅读时间需要 17 分钟。

题目:

http://codeforces.com/contest/1011/problem/D

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 1xm1≤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 (1ym1≤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, …, (n1)(n−1)-th, nn-th, 11-st, 22-nd, 33-rd, …, (n1)(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 (1m1091≤m≤109, 1n301≤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 (1ym1≤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 2311231−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 (1xm1091≤x≤m≤109, 1n301≤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.

Example
input
5 2 1 -1 -1 1 0
output
1 2 4 5 3 题意:互动问题,告诉你一个数m,让你在1到m之间猜一个数x,你每次询问系统会告诉你三种答案:0(猜对了),1(猜小了),-1(猜大了),但是系统告诉你的不一定是真话(/TДT)/, 系统有一个长度为n(n<=30)的由0和1组成的数组,你知道n但不知道数组具体内容,系统回答时会按照该数组顺序来,如果a[i]==1,他会正确回答,如果a[i]==0,他会回答相反数. 即第一次询问系统根据a[1]来确定是否给出正确的回答,第2次看a[2],……第n次看a[n],第n+1次看a[1],循环. 在不超过60次询问下问出正确答案(即系统回答0则正确); 思路: 前n次询问边界(1或m)确定该数组,之后就用二分的问法去寻找答案. 代码:
#include
#define fi first#define se second#define INF 0x3f3f3f3f#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)#define pqueue priority_queue#define NEW(a,b) memset(a,b,sizeof(a))const double pi=4.0*atan(1.0);const double e=exp(1.0);const int maxn=3e6+8;typedef long long LL;typedef unsigned long long ULL;//typedef pair
P;const LL mod=1e9+7;using namespace std;int a[110];int main(){ int m,n; cin>>m>>n; int x; int cnt=0; while(1){ cout<<1<
>x; if(x==0){ return 0; } if(x==-1){ a[cnt++]=-1; } else if(x==1){ a[cnt++]=1; } if(cnt==n){ break; } } int l=1; int r=m+1; int i=0; while(1){ int mid=(l+r)/2; cout<
<
>x; if(x==0){ return 0; } if(a[i]==-1){ x=-x; } i++; if(i==n){ i=0; } if(x==-1){ r=mid; } else if(x==1){ l=mid+1; } }}

 

转载于:https://www.cnblogs.com/Profish/p/9378228.html

你可能感兴趣的文章
cdh_host
查看>>
iOS 使用fir、 蒲公英 进行内部测试
查看>>
如何在.ashx文件中使用Session對象
查看>>
监听器初始化Job、JobTracker相应TaskTracker心跳、调度器分配task源码级分析
查看>>
xcode中如何安装多个版本的模拟器
查看>>
搭建ELK 集群 rpm安装
查看>>
汇编程序--要术及编译过程
查看>>
使用 Linux 文件恢复工具
查看>>
Ubuntu下NDK环境搭建以及使用
查看>>
Android的apk下载和安装
查看>>
Ubuntu13.04 Eclipse下编译安装Hadoop插件及使用小例
查看>>
rt-thread是如何做到通过menuconfig配置将相应文件加入工程和从工程中除去
查看>>
作业2.1.2 安装并使用PMD
查看>>
Ubuntu 16.04 安裝Docker
查看>>
整理的linux面试运维题
查看>>
sublime 的简单应用1
查看>>
js String对象中常用方法小结(字符串操作)
查看>>
EasyUi基础学习(一)—基本组件(上)
查看>>
format格式化函数
查看>>
【转载】Android App应用启动分析与优化
查看>>