CF1064 E

题意

交互题, 本来应该是在平面上进行的.
实际上换成一条直线就可以, 其实换成在平面上更复杂一些.

Solution

假设(l)点是黑点, (r)处是白点, 那么就把下一个点的位置放置在(l + r / 2)处, 然后递归处理.

Code

#include <ctype.h>
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 39;

struct Node {
	int color, position;
	bool operator < (const Node &x) const {
		return color == x.color ? position < x.position : color < x.color;
	}
} p[N];
const int XXX = 4323;

bool Check(int position, int now) {
	string s;
	p[now].position = position;
	printf("%d %d
", XXX, position);
	fflush(stdout);
	cin >> s;
	if (s == "white") return p[now].color = 0;
	else return p[now].color = 1;
}

int main() {
	int n;
	scanf("%d", &n);
	int l = 1, r = 1e9, mid;
	for (int i = 1; i <= n; i += 1) {
		mid = l + r >> 1;
		if (Check(mid, i)) r = mid;
		else l = mid;
	}
	int res = 0;
	for (int i = 1; i < n; i += 1)
		std:: swap(p[i], p[i + 1]);
	std::sort(p + 1, p + 1 + n);
	for (int i = 2; i <= n; i += 1)
		if (p[i].color != p[i - 1].color) {
			res = p[i - 1].position + 1;
			break;  
		}  
	if (res) printf("%d %d %d %d
", XXX - 1, res - 1, XXX + 1, res), fflush(stdout);
	else printf("%d %d %d %d
", XXX - 1, res, XXX + 1, res), fflush(stdout);

	return 0;
}
原文地址:https://www.cnblogs.com/qdscwyy/p/9800439.html