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\ ...
随机推荐
- taro实战1
npm install -g @tarojs/cli //或 yarn global add @tarojs/cli
- 解决.Net Mvc跨域请求问题
针对ASP.NET MVC和ASP.NET Web API两种项目类型 1.针对ASP.NET MVC,只需要在web.config中添加如下的内容即可 <system.webServer> ...
- C# Note4:XML序列化和反序列化(含加密解密等)
前言 在项目中,我们经常用到各种配置文件,比如xml文件.binary文件等等,这里主要根据实践经验介绍下xml文件的序列化和反序列化(毕竟最常用). 实践背景:我要做一个用户管理功能,用户账号信息存 ...
- C++多态(静多态和动多态)
如今的C++已经是个多重泛型编程语言(multiparadigm programming lauguage),一个同时支持过程形式(procedural).面向对象形式(object-oriented ...
- vue 中的slot属性(插槽)的使用
总结如下: VUE中关于插槽的文档说明很短,语言又写的很凝练,再加上其和方法,数据,计算机等常用选项在使用频率,使用先后上的差别,这就有可能造成初次接触插槽的开发者容易产生“算了吧,回头再学,反正已经 ...
- 2017年前小纪(有关http的一些缓存理论知识)
position的top和bottom的区别:前者基准点定在top,后者基准点定在bottom. for-in 遍历属性的顺序不确定 手机端,line-height对光标大小非常有影响 有些css3属 ...
- Flutter的输入框TextField
TextFiled组件的API 先来看一下TextFiled的构造方法: const TextField({ Key key, this.controller, this.focusNode, thi ...
- python之tips(三)--为什么Python有相同的不可变对象id不同?
参考 : https://www.jianshu.com/p/0f6f0db0ce8f
- SQL Server2012中时间字段为DateTime和VarChar的区别
在设计数据库的时候varchar类型是一个非常常见的类型,很多字段都可以使用这个类型,所以有时候在设计数据库的时候就很容易习惯性设计该类型,比如说时间类型,我们既可以DateTime类型,又可以使用v ...
- SSH本地端口转发的理解
ssh -L 3307:127.0.0.1:3306 user@ssh-server -N 其中127.0.0.1:3306是指 ssh-server要访问资源的ip和端口 而3307则是隧道的开口, ...