原题链接:http://codeforces.com/contest/1040/problem/D

Subway Pursuit

This is an interactive problem.

In the Wonderful Metropolis of the Future, there is no need in subway train drivers. Due to the technological progress, they were replaced by the Artificial Intelligence (AI). Unfortunately, one day the predictions of sci-fi writers came true: the AI rebelled and now there is an uncontrollable train in the subway. It can be dangerous! Your task is to find the train and stop the AI.

The subway of the Metropolis is one line (regular straight line with no self-intersections) with nnn stations, indexed consecutively from 111 to nnn. At each moment the train is at some station. You need to determine the index of this station, so that the train would be secured.

To find the train, dispatcher Sarah gave you a gadget that allows you to select arbitrary numbers lll and r(l≤r)r (l≤r)r(l≤r), and then check, whether the train is located on a station with index between lll and rrr, inclusive. Unfortunately, recharging of the gadget takes some time (and every time you use it as soon as possible), so between two applications of the gadget the train can move to any station that is at most kkk stations away. Formally, if the train was at the station xxx when the gadget was applied, then at the next application of the gadget the train can appear at any station yyy such that max(1,x−k)≤y≤min(n,x+k)max(1,x−k)≤y≤min(n,x+k)max(1,x−k)≤y≤min(n,x+k).

Note that AI is not aware that you are trying to catch the train, so it makes all moves according to its predefined plan.

After an examination of the gadget you found that it is very old and can hold no more than 450045004500 applications, after which it will break and your mission will be considered a failure.

Can you find the station with the train using no more than 450045004500 applications of the gadgets?

Input

The first line contains two integers nnn and k(1≤n≤1018,0≤k≤10)k (1≤n≤10^{18}, 0≤k≤10)k(1≤n≤1018,0≤k≤10) — the number of stations and the maximum number of stations the train can move between two applications of the gadget.

Interaction

You can apply the gadget at most 450045004500 times. In order to apply the gadget you need to print two space-separated integers lll and r(1≤l≤r≤n)r (1≤l≤r≤n)r(1≤l≤r≤n). You will then receive either string “Yes”, if the train is between stations lll and rrr, inclusive, or string “No” otherwise. If l=rl=rl=rand you received “Yes”, then you found the train successfully, and your program must halt immediately.

Answer “Bad” instead of “Yes” or “No” means that you made an invalid query or made too many queries. Exit immediately after receiving “Bad” and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.

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

In order to hack, you should present a test in the following format.

The first line should contain three integers n,kn, kn,k and p(1≤n≤1018,0≤k≤10,1≤p≤n)p (1≤n≤10^{18}, 0≤k≤10, 1≤p≤n)p(1≤n≤1018,0≤k≤10,1≤p≤n) — the number of stations, the maximum number of stations the train can move between two applications of the gadget and the initial position of the train, respectively.

Each of the next 450045004500 lines should contain a single integer x(1≤x≤n)x (1≤x≤n)x(1≤x≤n) — the positions of the train after each query. Two consecutive positions (including the initial one) should not differ by more than kkk.

For example, the following lines are the first lines of the sample test.

10 2 5
5
3
5
7
7
...
Example
input

10 2
Yes
No
Yes
Yes

output

3 5
3 3
3 4
5 5

Note

In the first sample, the train was initially at the station 555, after the first application of the gadget it did not move, after the second application it moved to the station 333, and after the third application moved again to the station 555.

题解

先二分缩小区间长度,当觉得区间足够小时randrandrand一下。

代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,k,le,ri,mid,pos=1;
char ch[5];
bool ask(ll l,ll r)
{printf("%I64d %I64d\n",l,r);fflush(stdout);scanf("%s",ch);return ch[0]=='Y';
}
void in(){scanf("%I64d%I64d",&n,&k);}
void ac()
{srand(time(0));le=1,ri=n;for(;!ask(pos,pos);pos=rand()%(ri-le+1)+le,le=max(1ll,le-k),ri=min(n,ri+k))for(;ri-le>50;(ask(le,(mid=le+ri>>1))?ri=mid:le=mid+1),le=max(1ll,le-k),ri=min(n,ri+k));
}
int main(){in(),ac();}

CF1040D Subway Pursuit相关推荐

  1. codeforces 1039B Subway Pursuit【二分+随机】

    题目:戳这里 题意:一个点在[1,n]以内,我们可以进行4500次查询,每次查询之后,该点会向左或向右移动0~k步,请在4500次查询以内找到该点. 解题思路:一边二分,一边随机. 交互题似乎有好多是 ...

  2. L - Subway POJ - 2502

    L - Subway POJ - 2502 题意: 从 家出发步行与坐 subway 交替进行,问最小的时间花费,最终四舍五入答案为 整数 存图难 四舍五入: double b int a = b + ...

  3. 8.正交匹配跟踪 Orthogonal Matching Pursuit (OMP)s

    OrthogonalMatchingPursuit and orthogonal_mp 实现了一个用来逼近在非零系数的个数上加约束的线性模型的拟合的OMP算法(比如L 0 pseudo-norm) 和 ...

  4. UA MATH567 高维统计专题1 稀疏信号及其恢复4 Basis Pursuit的算法 Projected Gradient Descent

    UA MATH567 高维统计专题1 稀疏信号及其恢复4 Basis Pursuit的算法 Projected Gradient Descent 前三讲完成了对sparse signal recove ...

  5. PAT甲级1131 Subway Map (30分):[C++题解]堆优化dijkstra、单源最短路、地铁地图、巧妙地建图套dijkstra模板!!

    文章目录 题目分析 题目链接 题目分析 原题: 来源:acwing 分析: 建图:所有能走到的点之间建立一条边,比如下面一条地铁线路有4站,它们是相通的,两两之间建一条边,边权是经过的站点数. 下面考 ...

  6. On the Difference Between Orthogonal Matching Pursuit and Orthogonal Least Squares

    摘要 当解被限定为稀疏的时候,也就是期望有更少的非零元素时,贪婪准则通常被用来解决不确定的可逆问题.OMP(正交匹配追踪法)和OLS通常被用来解决这两个问题.目前现有的文献中,有大量的文献都将这两者混 ...

  7. AtCoder Regular Contest 061 E - Snuke‘s Subway Trip(建图 + dijkstra最短路 / 0/1bfs / 并查集)

    AtCoder Regular Contest 061 E - Snuke's Subway Trip problem 洛谷翻译 my idea 最近一直在做网络流,所以一读这题后,我就想到了最小费用 ...

  8. 结对项目——Subway

    博客链接: 结对项目-Subway 转载于:https://www.cnblogs.com/Dominic-Abraham/p/9117266.html

  9. すぬけ君の地下鉄旅行 / Snuke's Subway Trip(AtCoder-2069)

    Problem Description Snuke's town has a subway system, consisting of N stations and M railway lines. ...

  10. Pure Pursuit纯跟踪算法Python/Matlab算法实现

    本文的python源代码来自: https://github.com/gameinskysky/PythonRobotics/blob/master/PathTracking/pure_pursuit ...

最新文章

  1. full calendar mysql_fullcalendar 及mysql数据库的工作日管理
  2. Vue v-if与v-show的区别
  3. jwt:token的解析
  4. Mysql 一条SQL语句实现批量更新数据,update结合case、when和then的使用案例
  5. 监督学习 | 线性回归 之正则线性模型原理及Sklearn实现
  6. 通过 NPOI 生成 Excel
  7. opencv学习笔记02
  8. 浏览器 刷新页面后回到顶部_当你在浏览器中,忘记了曾经的登录密码怎么办......
  9. 对集成电路的认识以及集成电路的重要性
  10. 5G时代的到来,对网络公关将产生哪些深远影响?
  11. 常见的商业数据库系统
  12. 彻底删除windos8 打印机驱动程序
  13. 微信或企业微信实现扫码登录的三种方式
  14. html中字的属性设置,html怎么设置字体属性
  15. 怎么从浩如烟海的书籍论文中找到有用信息?写论文、搞研究必看!
  16. 有关于3GPP SUL的一些学习
  17. Oracle表误操作恢复历史数据方法
  18. 25.(C语言)回文数判断万用公式
  19. java poi wps_POI操作WPS表格POI操作WPS表格.docx
  20. 苦战 自由软件的今生前世

热门文章

  1. 第一台全自动电子计算机,关于世界上第一台电子计算机ENIAC的叙述错误的是() senny全自动微电脑水位控制仪...
  2. 简单的maven自定义webapp目录
  3. C#调用存储过程,并且获得返回值和OutPut字符串
  4. 18华工校赛 小马哥的超级盐水 折半枚举
  5. CriminalIntent项目开发
  6. [Apio2012]dispatching 左偏树
  7. 配置RMAN备份环境
  8. Effectively bypassing kptr_restrict on Android
  9. 新浪微博客户端(33)-显示头像上的认证类型
  10. 用javascript操作xml