E. The penguin's game

time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Pay attention: this problem is interactive.

Penguin Xoriy came up with a new game recently. He has n icicles numbered from 1 to n. Each icicle has a temperature — an integer from 1 to 109. Exactly two of these icicles are special: their temperature is y, while a temperature of all the others is x ≠ y. You have to find those special icicles. You can choose a non-empty subset of icicles and ask the penguin what is the bitwise exclusive OR (XOR) of the temperatures of the icicles in this subset. Note that you can't ask more than 19 questions.

You are to find the special icicles.

Input

The first line contains three integers nxy (2 ≤ n ≤ 1000, 1 ≤ x, y ≤ 109, x ≠ y) — the number of icicles, the temperature of non-special icicles and the temperature of the special icicles.

Output

To give your answer to the penguin you have to print character "!" (without quotes), then print two integers p1, p2 (p1 < p2) — the indexes of the special icicles in ascending order. Note that "!" and p1 should be separated by a space; the indexes should be separated by a space too. After you gave the answer your program should terminate immediately.

Interaction

To ask a question print character "?" (without quotes), an integer c (1 ≤ c ≤ n), and c distinct integers p1, p2, ..., pc (1 ≤ pi ≤ n) — the indexes of icicles that you want to know about. Note that "?" and c should be separated by a space; the indexes should be separated by a space too.

After you asked the question, read a single integer — the answer.

Note that you can't ask more than 19 questions. If you ask more than 19 questions or at least one incorrect question, your solution will get "Wrong answer".

If at some moment your program reads  - 1 as an answer, it should immediately exit (for example, by calling exit(0)). You will get "Wrong answer" in this case, it means that you asked more than 19 questions, or asked an invalid question. If you ignore this, you can get other verdicts since your program will continue to read from a closed stream.

Your solution will get "Idleness Limit Exceeded", if you don't print anything or forget to flush the output, including for the final answer .

To flush you can use (just after printing):

  • fflush(stdout) in C++;
  • System.out.flush() in Java;
  • stdout.flush() in Python;
  • flush(output) in Pascal;
  • For other languages see the documentation.

Hacking

For hacking use the following format:

n x y pp2

Here 1 ≤ p1 < p2 ≤ n are the indexes of the special icicles.

Contestant programs will not be able to see this input.

Example input

4 2 1
2
1
1

output

? 3 1 2 3
? 1 1
? 1 3
! 1 3

Note

The answer for the first question is .

The answer for the second and the third questions is 1, therefore, special icicles are indexes 1 and 3.

You can read more about bitwise XOR operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR.

题意:

交互题,告诉你有 n (n<=1000) 个数(n 个数并不会告诉你),n 个数只含 x , y 两个数字,其中 y 只有两个。

可以对子集发起询问,对于你的每次询问会告诉你你所询问的子集的所有数的异或值,要求在19次询问内找到两个 y 的位置。

如:? 4 1 3 5 7 表示询问的子集包含四个元素{1, 3, 5, 7},则会返回{1, 3, 5, 7}所对应位置上的数字的异或值给你。

总结:

想了很长时间,题解也看了很长时间才有点头绪。

即:首先 n 个数按下标的二进制分成 10 个组(因为 n <= 1000,故 pow(2, 10) = 1024 > n)。

分组规则:对于一个下表 i (1 <= i <= n),可将其分在 i & (1 << bit) != 0 的组内,这样可保证每个数最多被分到 9 组;即对于每个数,它总会在某个集合中缺失。

这样就达到了将要找的两个 y 的分开的效果,可以保证存在这么两个组:分别包含不同的两个 y 。

对每个组可进行预处理,即可询问出两个 y 所在的组,设两个位置分别为 pos1、 pos2,通过预处理可求出 pos1 | pos2。

再对某个仅单独包含一个 y 的集合做二分查找,可求出一个 y 的位置,再通过异或求出另一个 y 的位置。

代码:

#include <bits/stdc++.h>
using namespace std;
int n, x, y;
int pos, pos1, pos2; int query(vector<int>& a)
{
int res=0;
if(a.size()!=0)
{
cout<<"? "<<a.size()<<" ";
for(int i=0; i<a.size(); ++i)
cout<<a[i]<<" ";
cout<<endl;
cin>>res;
}
return res;
} int slove(vector<int>& a)
{
int l=0, r=(int)a.size()-1;
while(l < r)
{
int m=(l+r)/2;
vector<int> b;
for(int i=l; i<=m; ++i)
b.push_back(a[i]);
int res=query(b);
if(res==y || res==(x^y))
r=m;
else
l=m+1;
}
return a[l];
} int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0); int bit=-1;
cin>>n>>x>>y;
for(int i=0; i<=9; ++i)
{
vector<int> a;
for(int j=1; j<=n; ++j)
if(j & (1<<i))
a.push_back(j);
int res=query(a);
if(res==y || res==(x^y))
{
pos |= (1<<i);
bit=i;
}
} vector<int> a, b;
for(int i=1; i<=n; ++i)
{
if(i & (1<<bit))
a.push_back(i);
else
b.push_back(i);
}
if(a.size() > b.size())
swap(a, b);
pos1=slove(a);
pos2=(pos^pos1);
if(pos1>pos2)
swap(pos1, pos2);
fflush(stdout);
cout<<"! "<<pos1<<" "<<pos2<<endl;
return 0;
}

Codeforces Round #427 (Div. 2) E. The penguin's game (交互题,二进制分组)的更多相关文章

  1. Codeforces Round #523 (Div. 2) F. Katya and Segments Sets (交互题+思维)

    https://codeforces.com/contest/1061/problem/F 题意 假设存在一颗完全k叉树(n<=1e5),允许你进行最多(n*60)次询问,然后输出这棵树的根,每 ...

  2. CodeForces 835C - Star sky | Codeforces Round #427 (Div. 2)

    s <= c是最骚的,数组在那一维开了10,第八组样例直接爆了- - /* CodeForces 835C - Star sky [ 前缀和,容斥 ] | Codeforces Round #4 ...

  3. CodeForces 835D - Palindromic characteristics | Codeforces Round #427 (Div. 2)

    证明在Tutorial的评论版里 /* CodeForces 835D - Palindromic characteristics [ 分析,DP ] | Codeforces Round #427 ...

  4. Codeforces Round #368 (Div. 2) A. Brain's Photos (水题)

    Brain's Photos 题目链接: http://codeforces.com/contest/707/problem/A Description Small, but very brave, ...

  5. Codeforces Round #427 (Div. 2) [ C. Star sky ] [ D. Palindromic characteristics ] [ E. The penguin's game ]

    本来准备好好打一场的,然而无奈腹痛只能带星号参加 (我才不是怕被打爆呢!) PROBLEM C - Star sky 题 OvO http://codeforces.com/contest/835/p ...

  6. Codeforces Round #427 (Div. 2) Problem D Palindromic characteristics (Codeforces 835D) - 记忆化搜索

    Palindromic characteristics of string s with length |s| is a sequence of |s| integers, where k-th nu ...

  7. Codeforces Round #427 (Div. 2) Problem C Star sky (Codeforces 835C) - 前缀和

    The Cartesian coordinate system is set in the sky. There you can see n stars, the i-th has coordinat ...

  8. Codeforces Round #427 (Div. 2) Problem A Key races (Codeforces 835 A)

    Two boys decided to compete in text typing on the site "Key races". During the competition ...

  9. Codeforces Round #427 (Div. 2) B. The number on the board

    引子: A题过于简单导致不敢提交,拖拖拉拉10多分钟还是决定交,太冲动交错了CE一发,我就知道又要错过一次涨分的机会.... B题还是过了,根据题意目测数组大小开1e5,居然蒙对,感觉用vector更 ...

随机推荐

  1. JVM-垃圾回收篇

    目录 JVM-垃圾回收篇 前言 举个例子 JVM 有哪些垃圾回收算法? 标记-清除算法 复制算法 标记-整理算法 分代收集算法 JVM 有哪些垃圾回收器? 概述 几个相关概念 一:Serial 收集器 ...

  2. CSS 常见样式 特殊用法 贯穿线&徽章&箭头

    贯穿渐变线,中间插值 如图: <h3 class="brief-modal-title"> <span>公告</span> </h3> ...

  3. Vue入门到精通

    Vue.js - Day1 课程介绍 前5天: 都在学习Vue基本的语法和概念:打包工具 Webpack , Gulp 后5天: 以项目驱动教学: 什么是Vue.js Vue.js 是目前最火的一个前 ...

  4. 【Netty之旅四】你一定看得懂的Netty客户端启动源码分析!

    前言 前面小飞已经讲解了NIO和Netty服务端启动,这一讲是Client的启动过程. 源码系列的文章依旧还是遵循大白话+画图的风格来讲解,本文Netty源码及以后的文章版本都基于:4.1.22.Fi ...

  5. Unity 如何在窗口大小可以随意改变的情况下让游戏世界完整的显示在镜头中

    当我们开发游戏时,如果是开发手机游戏,屏幕窗口的比例是固定的,不会说在运行时改变的. 但是,PC端的游戏就不一定,我希望它能被用户随意拉扯,但完整的内容还是能显示出来,这里我直接放例子: 请注意黑色的 ...

  6. C# 9.0 新特性预览 - 顶级语句

    C# 9.0 新特性预览 - 顶级语句 前言 随着 .NET 5 发布日期的日益临近,其对应的 C# 新版本已确定为 C# 9.0,其中新增加的特性(或语法糖)也已基本锁定,本系列文章将向大家展示它们 ...

  7. kafka学习(四)kafka安装与命令行调用

    文章更新时间:2020/06/07 一.安装JDK 过程就不过多介绍了... 二.安装Zookeeper 安装过程可以参考此处~ 三.安装并配置kafka Kafka下载地址  http://kafk ...

  8. 论文阅读笔记: Multi-Perspective Sentence Similarity Modeling with Convolution Neural Networks

    论文概况 Multi-Perspective Sentence Similarity Modeling with Convolution Neural Networks是处理比较两个句子相似度的问题, ...

  9. spring注解(Component、依赖注入、生命周期、作用域)

    1.注解 注解就是一个类,使用@加上注解名称,开发中可以使用注解取代配置文件 2.@Component 取代<bean  class="">,@Component 取代 ...

  10. Spring源码系列(四)--spring-aop是如何设计的

    简介 spring-aop 用于生成动态代理类(底层是使用 JDK 动态代理或 cglib 来生成代理类),搭配 spring-bean 一起使用,可以使 AOP 更加解耦.方便.在实际项目中,spr ...