Codeforces.810D.Glad to see you!(交互 二分)
\(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!(交互 二分)的更多相关文章
- [Codeforces 865C]Gotta Go Fast(期望dp+二分答案)
[Codeforces 865C]Gotta Go Fast(期望dp+二分答案) 题面 一个游戏一共有n个关卡,对于第i关,用a[i]时间通过的概率为p[i],用b[i]通过的时间为1-p[i],每 ...
- Glad to see you! CodeForces - 810D (交互+二分)
This is an interactive problem. In the output section below you will see the information about flush ...
- 【二分+交互】codeforces B. Glad to see you!
codeforces.com/contest/809/problem/B 只需要找到2个被选中的,首先,注意到将区间二等分时左侧区间为[l,mid],右侧区间为[mid+1,r],dui(mid,mi ...
- Codeforces.1129E.Legendary Tree(交互 二分)
题目链接 \(Description\) 有一棵\(n\)个点的树.你需要在\(11111\)次询问内确定出这棵树的形态.每次询问你给定两个非空且不相交的点集\(S,T\)和一个点\(u\),交互库会 ...
- Codeforces.835E.The penguin's game(交互 按位统计 二分)
题目链接 \(Description\) 有一个长为\(n\)的序列,其中有两个元素为\(y\),其余全为\(x\).你可以进行\(19\)次询问,每次询问你给出一个下标集合,交互库会返回这些元素的异 ...
- Codeforces.862D.Mahmoud and Ehab and the binary string(交互 二分)
题目链接 \(Description\) 有一个长为\(n\)的二进制串,保证\(01\)都存在.你可以询问不超过\(15\)次,每次询问你给出一个长为\(n\)的二进制串,交互库会返回你的串和目标串 ...
- codeforces 810 D. Glad to see you!(二分+互动的输入方式)
题目链接:http://codeforces.com/contest/810/problem/D 题意:两个人玩一场游戏要猜出Noora选的f种菜的任意两种.一个人猜点另一个人回答 TAK如果 ,(x ...
- 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 ...
- Codeforces.714D.Searching Rectangles(交互 二分)
题目链接 \(Description\) 在一个\(n*n\)的二维平面中有两个不相交的整点矩形,每次可以询问两个矩形有几个完全在你给出的一个矩形中.200次询问内确定两个矩形坐标. \(Soluti ...
随机推荐
- Hadoop上传文件时报错: could only be replicated to 0 nodes instead of minReplication (=1)....
问题 上传文件到Hadoop异常,报错信息如下: org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /home/inpu ...
- scala 基础到高阶
本文打算对这小段时间学习 scala 以及 spark 编程技术做个小结,一来温故而知新,而来为以后查阅方便 spark scala 入门小例子 文本文件 UserPurchaseHistory.c ...
- Linux - 磁盘操作
Linux 磁盘常见操作 : df -Ph # 查看硬盘容量 df -T # 查看磁盘分区格式 df -i # 查看inode节点 如果inode用满后无法创建文件 du -h 目录 # 检测目录下所 ...
- Hive笔记之宏(macro)
一.啥是宏 宏可以看做是一个简短的函数,或者是对一个表达式取别名,同时可以将这个表达式中的一些值做成变量调用时传入,比较适合于做分析时为一些临时需要用到很多次的表达式操作封装一下取个简短点的别名来调用 ...
- js数组方法forEach,map,filter,every,some实现
Array.prototype.map = function(fun /*, thisp*/) { var len = this.length; if (typeof fun != "fun ...
- (A - 整数划分 HYSBZ - 1263)(数组模拟大数乘法)
题目链接:https://cn.vjudge.net/problem/HYSBZ-1263 题目大意:中文题目 具体思路:先进了能的拆成3,如果当前剩下的是4,就先不减去3,直接乘4,如果还剩2的话, ...
- Project Euler Problem5
Smallest multiple Problem 5 2520 is the smallest number that can be divided by each of the numbers f ...
- PHP回调函数及匿名函数概念与用法详解
1.回调函数 PHP的回调函数其实和C.Java等语言的回调函数的作用是一模一样的,都是在主线程执行的过程中,突然跳去执行设置的回调函数: 回调函数执行完毕之后,再回到主线程处理接下来的流程 而在ph ...
- mysql 日期操作 增减天数、时间转换、时间戳(转换)
http://hi.baidu.com/juntao_li/item/094d78c6ce1aa060f6c95d0b MySQL datediff(date1,date2):两个日期相减 date1 ...
- hdu 1166 线段树(单点增减 区间求和)
Sample Input1101 2 3 4 5 6 7 8 9 10Query 1 3Add 3 6Query 2 7Sub 10 2Add 6 3Query 3 10End Sample Outp ...