Not able to solve this problem during the contest (virtual participation).

The first observation is that if we can identify $N-1$ balls of which half is blue and the other half is red, then with these $N - 1$ balls we can identify the color of the rest $N+1$ balls.

It's not hard to note that if there are more blue balls than red balls among balls numbered from $l$ to $l + N - 1$ but less among balls numbered from $l + 1$ to $l + N$, we then know that

  1. The $l$-th ball and the $l+N$-th ball must be of different colors.
  2. The $l$-th ball must be blue and the $l+N$-th ball must be red.
  3. There are equal number of blue and red balls among balls numbered from $l + 1$ to $l+N - 1$.

The problem is whether such $l$ even exists? The answer is ,fortunately, YES.

Here comes the second interesting observation:

Let's assume without loss of generality, there are more blue balls than red balls among the first $N$ balls, then there must be more red balls among the last $N$ balls. So such $l$ as described above must exist, and we can find one using binary search which costs at most $\log_2 N + 1$ queries. When the binary search finishes, we get $l$ and the color of the $l$-th and $l+N$-th balls.

When $l$ is found, for each ball numbered from $1$ to $l - 1$ or from $l + N + 1$ to $2N$, we can know its color with a query. Note that exactly half of these $N - 1$ known balls are blue, so we can use these balls to identify color of balls numbered from $l + 1$ to $l + N -1$ in a similar way.

code

int main() {
int n;
cin >> n;
auto ask = [&](int l) {
cout > res;
return res.front();
};
char ml = ask(1);
int l = 1, r = n + 1; while (r - l > 1) {

int mid = l + (r - l) / 2;

if (ask(mid) == ml) {

l = mid;

} else {

r = mid;

}

}

vector ans(2 * n + 1);

ans[l] = ml;

ans[l + n] = ml == 'R' ? 'B' : 'R'; auto ask2 = [&](int pos) {

cout << '?';

for (int i = 1; i < n; i++) {

cout << ' ' << l + i;

}

cout << ' ' << pos << endl;

string res;

cin >> res;

return res.front();

};

// [l + 1, l + n)

rng (i, 1, 2 * n + 1) {

if (i < l || i > l + n) {

ans[i] = ask2(i);

}

}

auto ask3 = [&](int pos) {

cout << '?';

rng (i, 1, 2 * n + 1) {

if (i < l || i > l + n) {

cout << ' ' << i;

}

}

cout << ' ' << pos << endl;

string res;

cin >> res;

return res.front();

};

rng (i, l + 1, l + n) {

ans[i] = ask3(i);

} cout << "! ";

for (int i = 1; i <= 2 * n; i++) {

cout << ans[i];

}

cout << '\n';

return 0;

}

DISCO Presents Discovery Channel Code Contest 2020 Qual Task E. Majority of Balls的更多相关文章

  1. DISCO Presents Discovery Channel Code Contest 2020 Qual题解

    传送门 \(A\) 咕咕 int x,y; int c[4]={0,300000,200000,100000}; int res; int main(){ cin>>x>>y; ...

  2. IOCCC(The International Obfuscated C Code Contest)

    国际 C 语言混乱代码大赛(IOCCC, The International Obfuscated C Code Contest)是一项国际编程赛事,从 1984 年开始,每年举办一次(1997年.1 ...

  3. 【AtCoder】CODE FESTIVAL 2016 qual A

    CODE FESTIVAL 2016 qual A A - CODEFESTIVAL 2016 -- #include <bits/stdc++.h> #define fi first # ...

  4. 【AtCoder】CODE FESTIVAL 2016 qual B

    CODE FESTIVAL 2016 qual B A - Signboard -- #include <bits/stdc++.h> #define fi first #define s ...

  5. 【AtCoder】CODE FESTIVAL 2016 qual C

    CODE FESTIVAL 2016 qual C A - CF -- #include <bits/stdc++.h> #define fi first #define se secon ...

  6. CODE FESTIVAL 2017 qual B B - Problem Set【水题,stl map】

    CODE FESTIVAL 2017 qual B B - Problem Set 确实水题,但当时没想到map,用sort后逐个比较解决的,感觉麻烦些,虽然效率高很多.map确实好写点. 用map: ...

  7. CODE FESTIVAL 2017 qual B C - 3 Steps【二分图】

    CODE FESTIVAL 2017 qual B C - 3 Steps 题意:给定一个n个结点m条边的无向图,若两点间走三步可以到,那么两点间可以直接连一条边,已经有边的不能连,问一共最多能连多少 ...

  8. M-SOLUTIONS Programming Contest 2020 题解

    M-SOLUTIONS Programming Contest 2020 题解 目录 M-SOLUTIONS Programming Contest 2020 题解 A - Kyu in AtCode ...

  9. Atcoder CODE FESTIVAL 2017 qual B D - 101 to 010 dp

    题目链接 题意 对于一个\(01\)串,如果其中存在子串\(101\),则可以将它变成\(010\). 问最多能进行多少次这样的操作. 思路 官方题解 转化 倒过来考虑. 考虑,最终得到的串中的\(' ...

随机推荐

  1. leetcode解题报告(2):Remove Duplicates from Sorted ArrayII

    描述 Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For ex ...

  2. Codeforces Educational Codeforces Round 67

    目录 Contest Info Solutions A. Stickers and Toys B. Letters Shop C. Vasya And Array D. Subarray Sortin ...

  3. bzoj3508: 开灯

    题目链接 题解 设\(b[i]=a[i]\ xor\ a[i+1]\) 我们可以发现,修改只会改变\(b[l-1]\)和\(b[r]\) 然后发现\(b[i]=1\)的点最多\(2*k\)个 状压\( ...

  4. Windows Storage 驱动开发 葵花宝典 - 翻译

    Roadmap for Developing Windows Storage Drivers Last Updated: 4/20/2017   To create a storage driver, ...

  5. Python3操作YAML文件

    数据及配置文件之争 数据及文件通常有三种类型: 配置文件型:如ini,conf,properties文件,适合存储简单变量和配置项,最多支持两层,不适合存储多层嵌套数据 表格矩阵型:如csv,exce ...

  6. python 获取远程设备ip地址

    python2.7 #!/usr/bin/env python # Python Network Programming Cookbook -- Chapter - # This program is ...

  7. 创建jQuery节点对象

    现在的年轻人,经历旺盛,每天都熬夜,今天又晚了,现在才更新博客,今天更新jquery入门之对节点的操作,内容简单好掌握.认真的燥再来吧. 1.$("<li class="li ...

  8. CISCO实验记录九:NAT地址转换

    1.静态NAT地址转换 #ip nat inside source static 192.168.12.1 192.168.23.4 //将12.1转为23.4 必须精确到主机IP 而不能是某个网段 ...

  9. web前端——Vue.js基础学习

    近期项目的前端页面准备引入Vue.js,看了网上一些简介,及它和JQuery的对比,发现对于新入门的前端开发来说,Vue 其实也是比较适用的一个框架,其实用性不比JQuery差,感觉还挺有意思,于是研 ...

  10. CDN概念

    CDN的全称是Content Delivery Network,即内容分发网络.其目的是通过在现有的Internet中增加一层新的网络架构,将网站的内容发布到最接近用户的网络"边缘" ...