• (二分)Codeforces Round #415 (Div. 2) D-Glad to see you!


    This is an interactive problem. In the output section below you will see the information about flushing the output.

    On Sunday Leha the hacker took Nura from the house where she lives and went with her to one of the most luxurious restaurants in Vičkopolis. Upon arrival, they left the car in a huge parking lot near the restaurant and hurried inside the building.

    In the restaurant a polite waiter immediately brought the menu to Leha and Noora, consisting of n dishes. It is interesting that all dishes in the menu are numbered with integers from 1 to n. After a little thought, the girl ordered exactly k different dishes from available in the menu. To pass the waiting time while the chefs prepare ordered dishes, the girl invited the hacker to play a game that will help them get to know each other better.

    The game itself is very simple: Noora wants Leha to guess any two dishes among all ordered. At the same time, she is ready to answer only one type of questions. Leha can say two numbers x and y (1 ≤ x, y ≤ n). After that Noora chooses some dish a for the number x such that, at first, a is among the dishes Noora ordered (x can be equal to a), and, secondly, the value  is the minimum possible. By the same rules the girl chooses dish b for y. After that Noora says «TAK» to Leha, if , and «NIE» otherwise. However, the restaurant is preparing quickly, so Leha has enough time to ask no more than 60 questions. After that he should name numbers of any two dishes Noora ordered.

    Help Leha to solve this problem!

    Input

    There are two numbers n and k (2 ≤ k ≤ n ≤ 105) in the single line of input denoting the number of dishes in the menu and the number of dishes Noora ordered.

    Output

    If you want to provide an answer, output a string of the form x y(1 ≤ x, y ≤ n, x ≠ y), if you think the dishes x and y was among dishes ordered by Noora. After that, flush the output and terminate your program.

    Example

    Input
    3 2
    NIE
    TAK
    NIE
    TAK
    TAK
    TAK
    Output
    1 1 2
    1 2 1
    1 1 3
    1 3 1
    1 2 3
    1 3 2
    2 2 3

    Note

    There are three dishes in sample. Noora ordered dished numberes 2 and 3, which Leha should guess. If Noora receive requests for the first dish (x = 1), then she'll choose the second dish (a = 2) as the dish with the minimum value . For the second (x = 2) and the third (x = 3) dishes themselves will be optimal, because in that case .

    Let Leha asks Noora about the next couple of dishes:

    • x = 1, y = 2, then he'll recieve «NIE» answer, because |1 - 2| > |2 - 2|
    • x = 2, y = 1, then he'll recieve «TAK» answer, because |2 - 2| ≤ |1 - 2|
    • x = 1, y = 3, then he'll recieve «NIE» answer, because |1 - 2| > |3 - 3|
    • x = 3, y = 1, then he'll recieve «TAK» answer, because |3 - 3| ≤ |1 - 2|
    • x = 2, y = 3, then he'll recieve «TAK» answer, because |2 - 2| ≤ |3 - 3|
    • x = 3, y = 2, then he'll recieve «TAK» answer, because |3 - 3| ≤ |2 - 2|

    According to the available information, it is possible to say that Nura ordered dishes with numbers 2 and 3.

    交互式的机制比较麻烦。

    只需要找到2个被选中的,首先,注意到将区间二等分时左侧区间为[l,mid],右侧区间为[mid+1,r],dui(mid,mid+1)进行询问,就可以得到这两个区间中哪个最近的离边界最近(如果不存在,距离可理解为无穷远),这样就确保了某一个区间必定存在至少一个被选中的,重复此过程,就一定能找到一个被选中的,设该位置为x。k>=2 所以此位置左侧、右侧中至少有一个有。先对左侧重复该过程,对结果进行和x的询问。因为如果那个位置是被选定的,则结果一定为0<=0,如果符合,直接输出,不然一定在右侧区域,对右侧区域重复该过程即可。

     1 #include <iostream>
     2 #include <string>
     3 #include <algorithm>
     4 #include <cstring>
     5 #include <cstdio>
     6 #include <cmath>
     7 #include <queue>
     8 #include <set>
     9 #include <map>
    10 #include <list>
    11 #include <vector>
    12 #include <stack>
    13 #define mp make_pair
    14 #define MIN(a,b) (a>b?b:a)
    15 #define MAX(a,b) (a>b?a:b)
    16 typedef long long ll;
    17 typedef unsigned long long ull;
    18 const int MAX=1e6+105;
    19 const int INF=1e9+5;
    20 const double M=4e18;
    21 using namespace std;
    22 const int MOD=1e9+7;
    23 typedef pair<int,int> pii;
    24 const double eps=0.000000001;
    25 int n,k;
    26 bool query(int x,int y)
    27 {
    28     if(x<0||y>n)
    29         return false;
    30     string re;
    31     cout<<1<<" "<<x<<" "<<y<<"
    ";
    32     cin>>re;
    33     return re=="TAK";
    34 }
    35 int get(int l,int r)
    36 {
    37     if(l>r)
    38         return -1;
    39     while(l<r)
    40     {
    41         int mid=(l+r)/2;
    42         if(query(mid,mid+1))
    43             r=mid;
    44         else
    45             l=mid+1;
    46     }
    47     return l;
    48 }
    49 int main()
    50 {
    51     scanf("%d%d",&n,&k);
    52     int x,y;
    53     x=get(1,n);
    54     y=get(1,x-1);
    55     if(!query(y,x))
    56         y=get(x+1,n);
    57     printf("2 %d %d
    ",x,y);
    58     return 0;
    59 }
  • 相关阅读:
    解决 'mvn' 不是内部或外部命令,也不是可运行的程序 或批处理文件。
    关于IDEA的Maven打jar包springboot项目问题,打成可执行jar包,IDEA创建的maven项目和spring initializr项目
    Flink接收RabbitMQ数据写入到Oracle
    操作MongoDB好用的图形化工具,Robomongo -> 下载 -> 安装
    PL/SQL Developer -> 下载 -> 安装 ->执行SQL -> 设置本地/远程连接
    MongoDB学习笔记,基础+增删改查+索引+聚合...
    SpringBoot整合MongoDB JPA,测试MongoRepository与MongoTemplate用法,简单增删改查+高级聚合
    Elasticsearch没看文档之前,整理的一些知识
    Elasticsearch中文文档,内容不全
    Elasticsearch 7.4.0官方文档操作
  • 原文地址:https://www.cnblogs.com/quintessence/p/6886601.html
Copyright © 2020-2023  润新知