CodeForces 809B Glad to see you!

Glad to see you!

题解:

交互题一般都是需要用二分去完成。

在二分时候每次检查左边和右边哪边会和答案更近, 然后在更近的那段新区间去重复检查, 知道区间长度为1。

在检查的时候,可以使得答案更近贴近于左边,或者右边。

 

代码:

#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod =  (int)1e9+7;
const int N = 2e5 + 100;
char s[N];
int solve(int l, int r){
    while(l != r){
        int mid1 = l+r >> 1;
        int mid2 = mid1 + 1;
        printf("1 %d %d\n", mid2, mid1);
        fflush(stdout);
        scanf("%s", s);
        if(s[0] == 'T') l = mid2;
        else  r = mid1;
    }
    return l;
}
int solve2(int l, int r){
    while(l != r){
        int mid1 = l+r >> 1;
        int mid2 = mid1+1;
        if((l+r)%2 == 0){
            mid1--;
            mid2--;
        }
        printf("1 %d %d\n", mid1, mid2);
        fflush(stdout);
        scanf("%s", s);
        if(s[0] == 'T') r = mid1;
        else  l = mid2;
    }
    return l;
}
int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    int p1 = solve(1, n);
    int p2 = solve2(1, p1);
    int p3 = solve(p1, n);
    int a[3] = {p1, p2, p3};
    sort(a, a+3);
    printf("2 %d %d\n", a[0], a[2]);
    fflush(stdout);
    return 0;
}
View Code

 

posted @ 2019-05-18 15:27  Schenker  阅读(227)  评论(0编辑  收藏  举报