codeforces.com/contest/809/problem/B

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

【Accepted】

 #include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <ctime>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=1e5+;
int n,k;
bool query(int x,int y)
{
if(x<=||y>n)
return false;
string res;
cout<<"1 "<<x<<" "<<y<<endl;
cin>>res;
return res=="TAK";
}
int get(int l,int r)
{
if(l>r)
{
return -;
}
while(l<r)
{
int mid=(l+r)>>;
if(query(mid,mid+))
{
r=mid;
}
else
{
l=mid+;
}
}
return l;
}
int main()
{ cin>>n>>k;
int x,y;
x=get(,n);
y=get(,x-);
if(!query(y,x))
{
y=get(x+,n);
}
cout<<"2 "<<x<<" "<<y<<endl;
return ;
}

注意:

get函数和query函数没有if判断,就会出错,比如x为1

而且在左侧找到了y之后要判断是否符合。

不要用while(~scanf()),只读单组;print之后fflush(stdout)否则IDLENESS LIMIT EXCEEDED

【二分+交互】codeforces B. Glad to see you!的更多相关文章

  1. Codeforces.810D.Glad to see you!(交互 二分)

    题目链接 \(Description\) 有一个大小为\(k\)的集合\(S\),元素两两不同且在\([1,n]\)内.你可以询问不超过\(60\)次,每次询问你给出\(x,y\),交互库会返回\(\ ...

  2. Codeforces Round #551 (Div. 2) E 二分 + 交互

    https://codeforces.com/contest/1153/problem/E 题意 边长为n的正方形里面有一条蛇,每次可以询问一个矩形,然后会告诉你蛇身和矩形相交有几部分,你需要在最多2 ...

  3. CodeForces 809B Glad to see you!

    Glad to see you! 题解: 交互题一般都是需要用二分去完成. 在二分时候每次检查左边和右边哪边会和答案更近, 然后在更近的那段新区间去重复检查, 知道区间长度为1. 在检查的时候,可以使 ...

  4. 【二分】Codeforces 706B Interesting drink

    题目链接: http://codeforces.com/problemset/problem/706/B 题目大意: n (1 ≤ n ≤ 100 000)个商店卖一个东西,每个商店的价格Ai,你有m ...

  5. 【二分】Codeforces Round #435 (Div. 2) D. Mahmoud and Ehab and the binary string

    题意:交互题:存在一个至少有一个0和一个1的长度为n的二进制串,你可以进行最多15次询问,每次给出一个长度为n的二进制串,系统返回你此串和原串的海明距离(两串不同的位数).最后要你找到任意一个0的位置 ...

  6. CodeChef - ELHIDARR Find an element in hidden array(二分交互)

    Find an element in hidden array There is an array of length N consisting of non-negative integers. T ...

  7. 【贪心+二分】codeforces D. Magazine Ad

    codeforces.com/contest/803/problem/D [题意] 给定一个字符串,字符串里可能有空格和连字符‘-’,空格和连字符的意义是一样的,都表示:能在那个位置把字符串分成两部分 ...

  8. 【贪心+二分】codeforces C. Sagheer and Nubian Market

    http://codeforces.com/contest/812/problem/C [题意] 如何花最少的钱买最多的纪念品?首要满足纪念品尽可能多,纪念品数量一样花钱要最少,输出纪念品数量以及最少 ...

  9. Forethought Future Cup - Elimination Round C 二分 + 交互(求树的直径)

    https://codeforces.com/contest/1146/problem/C 题意 一颗大小为n的树,每次可以询问两个集合,返回两个集合中的点的最大距离,9次询问之内得出树的直径 题解 ...

随机推荐

  1. Spring------自动化装配Bean(二)

    上一篇是基于 @ComponentScan自动装配Bean的实现,这一篇将通过java手动装配bean来实现. 手动装配相对于自动装配的优点: 可以自行定义Bean的各个属性. 添加额外的方法调度. ...

  2. (转)配置Spring管理的bean的作用域

    http://blog.csdn.net/yerenyuan_pku/article/details/52833477 Spring管理的bean的作用域有: singleton 在每个Spring ...

  3. Android主题更换换肤

    知识总览android主题换肤通常借助LayoutInflater#setFactory实现换肤. 换肤步骤: 通过解析外部的apk压缩文件,创建自定义的Resource对象去访问apk压缩文件的资源 ...

  4. 基于VueJS的render渲染函数结合自定义组件打造一款非常强大的IView 的Table

    基于VueJS的render渲染函数结合自定义组件打造一款非常强大的IView 的Table https://segmentfault.com/a/1190000015970367

  5. k8s集群之Docker安装镜像加速器配置与k8s容器网络

    安装Docker 参考:https://www.cnblogs.com/rdchenxi/p/10381631.html 加速器配置 参考:https://www.cnblogs.com/rdchen ...

  6. Ubuntu的防火墙配置-ufw-iptables

    自打2.4版本以后的Linux内核中, 提供了一个非常优秀的防火墙工具.这个工具可以对出入服务的网络数据进行分割.过滤.转发等等细微的控制,进而实现诸如防火墙.NAT等功能.一般来说, 我们会使用名气 ...

  7. No-3.Linux 终端命令格式

    Linux 终端命令格式 01. 终端命令格式 command [-options] [parameter] 说明: command:命令名,相应功能的英文单词或单词的缩写 [-options]:选项 ...

  8. docker run之后状态总是Exited

    add -it docker run -it -name test -d nginx:latest /bin/bash

  9. luogu P2865 路障

    https://www.luogu.org/problemnew/show/P2865 看到题解好多dijkstra,作为一名钟爱于spfa的蒟蒻看不下去了. 有些spfa要跑两边,代码量要曾长好多( ...

  10. hdu3094 A tree game

    题目描述 题解: 树上删边. $SG[u]$^=$SG[son[u]]+1$ 代码: #include<cstdio> #include<cstring> ; template ...