前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >cf1064E. Dwarves, Hats and Extrasensory Abilities(二分 交互)

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

作者头像
attack
发布2018-10-15 12:53:17
5291
发布2018-10-15 12:53:17
举报

题意

题目链接

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

Sol

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

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

  1. 二分调整边界的时候直接设\(l = mid\)或\(r = mid\),因为我们最后得到的不是一个精确解,所以这样写是可以的
  2. 最后输出直线的时候加一个偏移量,也就是输出一条斜线

具体看代码

代码语言:javascript
复制
/*
*/
#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
*/
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-10-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 题意
  • Sol
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档