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

## 题意

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

## Sol

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;
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() {
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 条评论

## 相关文章

12220

49820

14420

30920

13640

14920

14910

14630

10810

### ASP.NET web.config中<customErrors>节点说明

customErrors>节点用于定义一些自定义错误信息的信息。此节点有Mode和defaultRedirect两个属性，其中defaultRedirect属性...

8310