CF1064 E - Dwarves, Hats and Extrasensory Abilities
题意
交互题, 本来应该是在平面上进行的.
实际上换成一条直线就可以, 其实换成在平面上更复杂一些.
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的更多相关文章
- [Codeforces Round #516][Codeforces 1063C/1064E. Dwarves, Hats and Extrasensory Abilities]
题目链接:1063C - Dwarves, Hats and Extrasensory Abilities/1064E - Dwarves, Hats and Extrasensory Abiliti ...
- 【交互 细节题 思维题】cf1064E. Dwarves, Hats and Extrasensory Abilities
第一次做交互真有趣……:挺好的细节思维题 This is an interactive problem. In good old times dwarves tried to develop extr ...
- CodeForces 1063C. Dwarves, Hats and Extrasensory Abilities 交互
题目大意: 依次给定$n$个点的颜色,要求给定这$n$个点的坐标以及一条可以把他们分成两部分的直线 强制在线(交互) $n \leqslant 30$ 感觉自己真像一个乱搞... 我们只考虑把点放在最 ...
- cf1064E. Dwarves, Hats and Extrasensory Abilities(二分 交互)
题意 题目链接 \(n\)次操作,每次你给出一个点的坐标,系统会返回该点的颜色(黑 / 白),程序最后输出一条直线把所有黑点和白点分隔开 Sol 一个很直观的想法:首先询问\((dx, 0)\),然后 ...
- 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 设黑点放直线上方:如果已知( ...
- Codeforces Round #516 (Div. 2, by Moscow Team Olympiad)
题目链接 A. Make a triangle! 题意 让某段最少增加多少使得构成三角形 思路 让较小两段往最长段去凑 代码 #include <bits/stdc++.h> #defin ...
- Codeforces Round #516 (Div. 2) (A~E)
目录 Codeforces 1064 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Lab ...
- Codeforces Round #516(Div 2)
比赛链接:传送门 A. Make a triangle!(简单思维) 题目大意: 给你三条边,问你最多加多少长度能使这三条边能构成三角形. 思路: 最大边小于答案加另外两条边的和. #include ...
随机推荐
- BZOJ3669:[NOI2014]魔法森林——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=3669 https://www.luogu.org/problemnew/show/P2387 为了得 ...
- 2017 ccpc哈尔滨 A题 Palindrome
2017 ccpc哈尔滨 A题 Palindrome 题意: 给一个串\(T\),计算存在多少子串S满足\(S[i]=S[2n−i]=S[2n+i−2](1≤i≤n)\) 思路: 很明显这里的回文串长 ...
- android getpost代码
GetPostUtil public class GetPostUtil { /** * 向指定URL发送GET方法的请求 * * @param url * 发送请求的URL * @param par ...
- 关于JavaScript的沙箱模式
从语言学的角度上来说,允许代码无节制地使用全局变量,是最错误的选择之一.而更可怕的,就是一个变量"可能"成为全局的(在未知的时间与地点).但是这两项,却伴随JavaScript这门 ...
- SELECT LOCK IN SHARE MODE and FOR UPDATE
Baronwrote nice article comparing locking hints in MySQL and SQL Server. In MySQL/Innodb LOCK IN SHA ...
- POJ2155 树状数组
Matrix Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 26650 Accepted: 9825 Descripti ...
- Android Eclipse 开发环境搭建
因为开发工具版本 搭建 环境配置经常出现问题 再次用一篇随笔来做下记录 1 需要的工具jdk-6u45-windows-x64 //http://www.oracle.com/technetwork/ ...
- kafka 命令笔记
以下命令都是在kafka根目录下 启动自带的zookeeper bin/zookeeper-server-start.sh config/zookeeper.properties 启动kafka(启动 ...
- 关于android中PendingIntent.getBroadcase的注册广播
使用语句 PendingIntent intent= PendingIntent.getBroadcast(Context context, int requestCode, Intent inten ...
- 关于MyBatis一些小错误,元素内容必须由格式正确的字符数据或标记组成.
今天在Mapper.xml文件写查询语句报了个奇怪的错误 Caused by: org.apache.ibatis.builder.BuilderException: Error creating d ...