cf1088D Ehab and another another xor problem (构造)
题意:有两数a,b,每次你可以给定c,d询问a xor c和b xor d的大小关系,最多询问62次($a,b<=2^{30}$),问a和b
考虑从高位往低位做,正在做第i位,已经知道了a和b的前i-1位
这样的话,只要让a、c,b、d的前i-1位相同,就和前i-1位没关系了

考虑在第i位上abcd的情况对应的回答(后面的位数都给0),其中~表示与第i位后面的相关
那我可以分别用01 10询问两次,如果是先大后小或是先小后大,就能判断出是00或者11
但如果前后两次相同,那就有可能是01或者10
考虑上一次两次相同的时候是在第j位,具体到底是大于还是小于
然后又因为j+1~i-1位它们a和b都是相同的,所以这个大于还是小于就取决于第i位,所以能得出是01还是10
如果这是第一次相同,那直接再拿00询问一次就可以得到答案
一共61次
#include<bits/stdc++.h>
#define pa pair<int,int>
#define CLR(a,x) memset(a,x,sizeof(a))
#define MP make_pair
using namespace std;
typedef long long ll;
const int maxn=; inline char gc(){
return getchar();
static const int maxs=<<;static char buf[maxs],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,,maxs,stdin),p1==p2)?EOF:*p1++;
}
inline ll rd(){
ll x=;char c=gc();bool neg=;
while(c<''||c>''){if(c=='-') neg=;c=gc();}
while(c>=''&&c<='') x=(x<<)+(x<<)+c-'',c=gc();
return neg?(~x+):x;
} inline int get(int c,int d){
printf("? %d %d\n",c,d);
fflush(stdout);
return rd();
} int main(){
//freopen("","r",stdin);
int i;
int cp=,dp=;
int a=,b=;
int lst=;
for(i=;i>=;i--){
int v1=get(cp,dp|(<<i)),v2=get(cp|(<<i),dp);
if(v1==v2){
if(lst==) a|=(<<i);
else if(lst==-) b|=(<<i);
else{
if(get(cp,dp)==) a|=(<<i);
else b|=(<<i);
}
lst=v1;
}else if(v1==) a|=(<<i),b|=(<<i);
cp=a,dp=b;
}
printf("! %d %d\n",a,b);
fflush(stdout);
return ; }
cf1088D Ehab and another another xor problem (构造)的更多相关文章
- 【CF1174D】 Ehab and the Expected XOR Problem - 构造
题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...
- cf1088D. Ehab and another another xor problem(思维)
题意 题目链接 系统中有两个数\((a, b)\),请使用\(62\)以内次询问来确定出\((a, b)\) 每次可以询问两个数\((c, d)\) 若\(a \oplus c > b \opl ...
- CF1088D Ehab and another another xor problem
思路: 根据异或的性质一位一位来搞.参考了https://blog.lucien.ink/archives/362/ 实现: #include <bits/stdc++.h> using ...
- Codeforces Round #525 D - Ehab and another another xor problem /// 构造
题目大意: 本题有两个隐藏起来的a b(1<=a,b<=1e30) 每次可 printf("? %d %d\n",c,d); 表示询问 a^c 与 b^d 的相对大小 ...
- Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem
D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...
- codeforces#1157D. Ehab and the Expected XOR Problem(构造)
题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...
- CF D. Ehab and the Expected XOR Problem 贪心+位运算
题中只有两个条件:任意区间异或值不等于0或m. 如果只考虑区间异或值不等于 0,则任意两个前缀异或值不能相等. 而除了不能相等之外,还需保证不能出现任意两个前缀异或值不等于m. 即 $xor[i]$^ ...
- Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)
参考资料: [1]:https://blog.csdn.net/weixin_43790474/article/details/84815383 [2]:http://www.cnblogs.com/ ...
- Codeforces.1088D.Ehab and another another xor problem(交互 思路)
题目链接 边颓边写了半上午A掉啦233(本来就是被无数人过掉的好吗→_→) 首先可以\(Query\)一次得到\(a,b\)的大小关系(\(c=d=0\)). 然后发现我们是可以逐位比较出\(a,b\ ...
随机推荐
- mac下的快捷键
功能 快捷键 通用 打开新窗口 command + n 打开新标签 command + t 关闭标签 command + w 缩小 command - 放大 command + 全屏.取消全屏 com ...
- mysql问题汇总——持续更新
1.this is incompatible with sql_mode=only_full_group_by set @@sql_mode='STRICT_TRANS_TABLES,NO_ZERO_ ...
- css实现三栏自适应布局(两边固定,中间自适应)以及优缺点
方法一:绝对定位(absolute + margin) 原理:给左右两边的元素设置absolute,这样左右两边的元素脱离标准文档流的控制,中间的元素自然会上来,然后给中间的元素设置margin留出左 ...
- 面试题(校招java)
1:linux线程和进程的区别? 进程是程序执行时的一个实例,即它是程序已经执行到课中程度的数据结构的汇集.从内核的观点看,进程的目的就是担当分配系统资源(CPU时间.内存等)的基本单位. 线程是进程 ...
- 安装MongoDB(做成Windows服务)并加载C#驱动程序
一 Mongodb简介: 通过查询网上的一些信息来介绍一下Mongodb的优势:MongoDB是一个面向文档的数据库,目前由10gen开发并维护,它的功能丰富,齐全,完全可以替代MySQL.在使用Mo ...
- Yii2控制台命令
Yii2控制台表格输出: 例如: $in_sheet_number_queue = []; $wms_material_in_sheet_list = \core\models\WmsMaterial ...
- edge
https://www.cnblogs.com/st-leslie/p/6784990.html
- MySQL的FIND_IN_SET()函数
今天在做项目时,看到了一个从没见过的MySQL函数——FIND_IN_SET(),顿时就产生了浓郁的兴趣,然后就搜了搜,翻了翻. 语法:FIND_IN_SET(str,strlist) 定义: 1. ...
- 启用chacha20和salsa20等加密方法
wget https://download.libsodium.org/libsodium/releases/LATEST.tar.gz tar zxf LATEST.tar.gz cd libsod ...
- How to create DMG on macOS
hdiutil create -srcfolder /users/test1/ -volname test1 /users/test/test1.dmg