题目链接

\(Description\)

  有一个大小为\(k\)的集合\(S\),元素两两不同且在\([1,n]\)内。你可以询问不超过\(60\)次,每次询问你给出\(x,y\),交互库会返回\(\left[\ \min(|x-a|,a\in S)\leq \min(|y-a|,a\in S)\ \right]\)是(TAK)否(NIE)为真。求任意两个一定在集合\(S\)中出现过的数。

\(Solution\)

  考虑对区间\([l,r]\)二分,若Check(mid,mid+1)==1,则区间\([1,mid]\)中一定存在一个数;否则区间\([mid+1,r]\)中一定存在一个数。这样用\(\log10^5=16\)次可以确定一个数\(A\)。

  对于第二个数,可以在\([1,A-1]\)和\([A+1,n]\)中分别二分。

#include <cstdio>
#include <cctype>
#define gc() getchar()
const int N=1e5+5; int n; inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
}
inline bool Query(int x,int y)
{
static char s[7];
if(y>n) return 1;//!
printf("1 %d %d\n",x,y); fflush(stdout);
return scanf("%s",s),s[0]=='T';
}
int Check(int l,int r)
{
if(l>r) return 0;
int mid,ans=0;
while(l<=r)
if(mid=l+r>>1, Query(mid,mid+1)) ans=mid,r=mid-1;
else l=mid+1;
return ans;
} int main()
{
n=read(); int K=read();
int A=Check(1,n), B=Check(1,A-1);
if(!B) B=Check(A+1,n);
printf("2 %d %d\n",A,B); fflush(stdout); return 0;
}

Codeforces.810D.Glad to see you!(交互 二分)的更多相关文章

  1. [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)

    [Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...

  2. Glad to see you! CodeForces - 810D (交互+二分)

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

  3. 【二分+交互】codeforces B. Glad to see you!

    codeforces.com/contest/809/problem/B 只需要找到2个被选中的,首先,注意到将区间二等分时左侧区间为[l,mid],右侧区间为[mid+1,r],dui(mid,mi ...

  4. Codeforces.1129E.Legendary Tree(交互 二分)

    题目链接 \(Description\) 有一棵\(n\)个点的树.你需要在\(11111\)次询问内确定出这棵树的形态.每次询问你给定两个非空且不相交的点集\(S,T\)和一个点\(u\),交互库会 ...

  5. Codeforces.835E.The penguin's game(交互 按位统计 二分)

    题目链接 \(Description\) 有一个长为\(n\)的序列,其中有两个元素为\(y\),其余全为\(x\).你可以进行\(19\)次询问,每次询问你给出一个下标集合,交互库会返回这些元素的异 ...

  6. Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)

    题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...

  7. codeforces 810 D. Glad to see you!(二分+互动的输入方式)

    题目链接:http://codeforces.com/contest/810/problem/D 题意:两个人玩一场游戏要猜出Noora选的f种菜的任意两种.一个人猜点另一个人回答 TAK如果 ,(x ...

  8. Codeforces Round #534 (Div. 2)D. Game with modulo-1104-D(交互+二分+构造)

    D. Game with modulo time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces.714D.Searching Rectangles(交互 二分)

    题目链接 \(Description\) 在一个\(n*n\)的二维平面中有两个不相交的整点矩形,每次可以询问两个矩形有几个完全在你给出的一个矩形中.200次询问内确定两个矩形坐标. \(Soluti ...

随机推荐

  1. CCNA学习与实验指南——第2章 网络互联和参考模型

    大三下学期的这个时间段,不知道是不是社会就业的恐惧与自身前途的迷茫所带来的压力,身边的同学一个个的整天奔赴考研室学的好不努力,空荡荡的宿舍只剩我一人孑然聊聊甚是索然无味,亦或许是即将毕业的压力等接踵而 ...

  2. info replication

    主Redis设置值:redis-cli -h 192.168.18.121 -p 63800 -a tinywan123456 登陆从1:redis-cli -h 192.168.18.121 -p ...

  3. python学习笔记6--操作Mysql

    一.mysql操作 import pymysql #连上mysql ip 端口号 密码 账号 数据库 #建立游标 #执行sql #获取结果 #关闭连接.关闭游标 conn=pymysql.connec ...

  4. [转载]Browser Link feature in Visual Studio Preview 2013

    http://blogs.msdn.com/b/webdev/archive/2013/07/29/10430221.aspx Browser Link feature in Visual Studi ...

  5. Internet Explorer 6 的15个讨厌的bug和简单的解决方法

    关于bug更全的,我推荐去这个网站hasLayout,整理的非常全!三年前就看了,最近手生,又翻出来看看~~虽然上面有很多bug讲解,但是我觉得目前用的比较多或者说是常见的应该属下面这篇文章,15 a ...

  6. argunlar 1.0.1 【数据绑定】

    <!DOCTYPE html><html lang="en" ng-app><head>    <meta charset="U ...

  7. 第12月第15天 mysqlx boost reswift

    1. INSTALL PLUGIN mysqlx SONAME 'mysqlx.so' https://yq.aliyun.com/articles/38288 2. boost boost::sha ...

  8. 爬虫笔记之刷小怪练级:yymp3爬虫(音乐类爬虫)

    一.目标 爬取http://www.yymp3.com网站歌曲相关信息,包括歌曲名字.作者相关信息.歌曲的音频数据.歌曲的歌词数据. 二.分析 2.1 歌曲信息.歌曲音频数据下载地址的获取 随便打开一 ...

  9. lucene查询索引之Query子类查询——(七)

    0.文档名字:(根据名字索引查询文档)

  10. python3之memcached

    1.memcached介绍 Memcached是一个自由开源的,高性能,分布式内存对象缓存系统. Memcached是以LiveJournal旗下Danga Interactive公司的Brad Fi ...