cf1064E. Dwarves, Hats and Extrasensory Abilities(二分 交互)
题意
\(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(二分 交互)的更多相关文章
- 【交互 细节题 思维题】cf1064E. Dwarves, Hats and Extrasensory Abilities
第一次做交互真有趣……:挺好的细节思维题 This is an interactive problem. In good old times dwarves tried to develop extr ...
- [Codeforces Round #516][Codeforces 1063C/1064E. Dwarves, Hats and Extrasensory Abilities]
题目链接:1063C - Dwarves, Hats and Extrasensory Abilities/1064E - Dwarves, Hats and Extrasensory Abiliti ...
- CodeForces 1063C. Dwarves, Hats and Extrasensory Abilities 交互
题目大意: 依次给定$n$个点的颜色,要求给定这$n$个点的坐标以及一条可以把他们分成两部分的直线 强制在线(交互) $n \leqslant 30$ 感觉自己真像一个乱搞... 我们只考虑把点放在最 ...
- CF1064 E - Dwarves, Hats and Extrasensory Abilities
题意 交互题, 本来应该是在平面上进行的. 实际上换成一条直线就可以, 其实换成在平面上更复杂一些. Solution 假设\(l\)点是黑点, \(r\)处是白点, 那么就把下一个点的位置放置在\( ...
- Codeforces #1063C Dwarves, Hats and Extrasensory Abilities
题目大意 交互题. 输出平面上的一个点的坐标,交互程序给这个点染色(白或黑). 如此重复 $n$ 次($ 1\le n \le 30$). 要求输出的 $n$ 个点各不相同,并且不论交互程序怎样给它们 ...
- Dwarves, Hats and Extrasensory Abilities Codeforces - 1063C
https://codeforces.com/contest/1063/problem/C 首先可以想到一个简单做法:先钦定这个直线的斜率k=-1,然后设直线y=-x+b 设黑点放直线上方:如果已知( ...
- CodeChef - ELHIDARR Find an element in hidden array(二分交互)
Find an element in hidden array There is an array of length N consisting of non-negative integers. T ...
- 【ECNU3542】神奇的魔术(二分交互题)
点此看题面 大致题意: 有一个\(1\sim 2^n\)的排列,\(n\le7\),每次交互告诉你有几个位置上的数是正确的,让你在\(1000\)轮以内猜出每个位置上的数. 二分 显然,我们可以通过二 ...
- Forethought Future Cup - Elimination Round C 二分 + 交互(求树的直径)
https://codeforces.com/contest/1146/problem/C 题意 一颗大小为n的树,每次可以询问两个集合,返回两个集合中的点的最大距离,9次询问之内得出树的直径 题解 ...
随机推荐
- Python描述符深入理解
Python的描述符乍眼看去简单,但是细节方面如果不注意容易掉坑,总结以下几个坑,以作备忘,先看代码: class D: def __get__(self, inst, owner): if inst ...
- [golang] go的typeswitch guard(类型区别)语法和type assertion(类型断言)语法
最近在实现golang,看到个go的特性语法: typeswitch guard. typeswitch guard语法如下: package main import "fmt" ...
- js 伪数组 arguments
/* 定义一个函数,如果不确定用户是否传入了参数, arguments可以获取到函数传入了多少个参数 和每个参数的值 */ /* 定义 */ function f1() { //获取的是函数在调用的时 ...
- setinterval 里面的方法记得加引号
setinterval 里面的方法记得加引号 否则不执行
- Java getMethod类型参数
public class DynamicInvoker { public static void main(String[] args) { // TODO Auto-generated method ...
- javascrip 词法分析详解
JavaScript的高级知识---词法分析 词法分析 词法分析方法: js运行前有一个类似编译的过程即词法分析,词法分析主要有三个步骤: 分析参数 再分析变量的声明 分析函数说明 函数在运行的瞬 ...
- rest-assured的默认值与Specification重用
一.默认值 rest-assured发起请求时,默认使用的host为localhost,端口为8080,如果你想使用不同的端口,你可以这样做: given().port(80)...... 或者是简单 ...
- 51Nod-1259-整数划分 V2
51Nod-1259-整数划分 V2 将N分为若干个整数的和,有多少种不同的划分方式,例如:n = 4,{4} {1,3} {2,2} {1,1,2} {1,1,1,1},共5种.由于数据较大,输出M ...
- tensorflow基础-placeholder
placeholder: 要给节点输入数据时用 placeholder,在 TensorFlow 中用placeholder 来描述等待输入的节点,只需要指定类型即可,然后在执行节点的时候用一个字典来 ...
- HDU - 3652 数位DP 套路题
题意:统计能被13整除和含有13的数的个数 解法没法好说的..学了前面两道直接啪出来了 PS.HDU深夜日常维护,没法交题,拿网上的代码随便对拍一下,输出一致 #include<bits/std ...