CF1064 E - Dwarves, Hats and Extrasensory Abilities
阿新 • • 發佈:2018-10-16
swa tdi span break ras pan type abi string
題意
交互題, 本來應該是在平面上進行的.
實際上換成一條直線就可以, 其實換成在平面上更復雜一些.
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\n", 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\n", XXX - 1, res - 1, XXX + 1, res), fflush(stdout); else printf("%d %d %d %d\n", XXX - 1, res, XXX + 1, res), fflush(stdout); return 0; }
CF1064 E - Dwarves, Hats and Extrasensory Abilities