cf1064E. Dwarves, Hats and Extrasensory Abilities(二分 交互)
阿新 • • 發佈:2018-10-15
iostream force ats unsigned har max 根據 abi ase
題意
題目鏈接
\(n\)次操作,每次你給出一個點的坐標,系統會返回該點的顏色(黑 / 白),程序最後輸出一條直線把所有黑點和白點分隔開
Sol
一個很直觀的想法:首先詢問\((dx, 0)\),然後每次詢問二分中點,根據與第一次詢問得到的字符串的關系不斷調整二分範圍
但是這樣會被卡,我修改了兩個地方才過。
二分調整邊界的時候直接設\(l = mid\)或\(r = mid\),因為我們最後得到的不是一個精確解,所以這樣寫是可以的
最後輸出直線的時候加一個偏移量,也就是輸出一條斜線
具體看代碼
/* */ #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 */
cf1064E. Dwarves, Hats and Extrasensory Abilities(二分 交互)