cf1064E. Dwarves, Hats and Extrasensory Abilities(二分 交互)

题意

题目链接

\(n\)次操作,每次你给出一个点的坐标,系统会返回该点的颜色(黑 / 白),程序最后输出一条直线把所有黑点和白点分隔开

Sol

一个很直观的想法:首先询问\((dx, 0)\),然后每次询问二分中点,根据与第一次询问得到的字符串的关系不断调整二分范围

但是这样会被卡,我修改了两个地方才过。

  1. 二分调整边界的时候直接设\(l = mid\)\(r = mid\),因为我们最后得到的不是一个精确解,所以这样写是可以的

  2. 最后输出直线的时候加一个偏移量,也就是输出一条斜线

具体看代码

/*
*/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/hash_policy.hpp>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
#define LL long long 
#define ull unsigned long long 
#define rg register 
#define pt(x) printf("%d ", x);
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
//char obuf[1<<24], *O = obuf;
//void print(int x) {if(x > 9) print(x / 10); *O++ = x % 10 + '0';}
//#define OS  *O++ = ' ';
//#define fout fwrite(obuf, O-obuf, 1 , stdout);
using namespace std;
//using namespace __gnu_pbds;
const int MAXN = 2005, INF = 1e9 + 10, mod = 1e9 + 7;
const int D[] = { -1, 1};
const double eps = 1e-9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

int N, Dx = 23333;
string s, pre;

main() {
    N = read();
    int l = 0, r = 1e9;
    printf("%d 0\n", Dx);
    fflush(stdout);
    cin >> pre;
    int ans = 0;
    for(int i = 2; i <= N; i++) {
        int mid = l + r >> 1;
        printf("%d %d\n", Dx, mid);
        fflush(stdout);
        cin >> s;
        if(s != pre) r = mid;
        else l = mid, ans = mid;
    }
    
    printf("%d %d %d %d", Dx - 3, ans, Dx + 3, ans + 1);
    return 0;
}
/*
5
black
black
white
white
black
*/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值