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\ ...
随机推荐
- 【问题解决方案】editplus中批量将ANSI转换为utf-8
来自一个用editplus写java程序但是上传到GitHub里中文乱码的故事 大致步骤: editplus全部打开之后(打开为何种编码不重要): (全部打开是指在左下方的文件列表选中-->右击 ...
- 数组建 BST
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int N, root = 1; int ...
- Es5中的类和静态方法 继承
Es5中的类和静态方法 继承(原型链继承.对象冒充继承.原型链+对象冒充组合继承) // es5里面的类 //1.最简单的类 // function Person(){ // this.name='张 ...
- AngularJS基于模块化的MVC实现
AngularJS基于模块化的MVC实现 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&qu ...
- Linux安装mysql5.6
安装mysql5.6https://www.cnblogs.com/wangdaijun/p/6132632.html
- SQL Server2012数据库开启远程连接
在我们使用SQL Server数据库的时候很重要的一点就是开启数据库的远程连接,这是因为很多时候数据库部署在远程的服务器上会比较方便,而部署在客户端的话,由于客户端不固定,所以需要经常去部署,这样容易 ...
- Python——进程通信之间数据共享
from multiprocessing import Manager,Process,Lock def main(dic,lock): lock.acquire() dic['count'] -= ...
- layui弹窗 之 iframe关闭
1)关闭特定iframe //当在iframe页面关闭自身时,在iframe页执行以下js脚本 var index = parent.layer.getFrameIndex(window.name); ...
- js函数使用prototype和不适用prototype的区别
js中类定义函数时用prototype与不用的区别 原创 2017年06月05日 12:25:41 标签: 函数 / prototype / class 首先来看一个实例: function Li ...
- Spring Boot 构建电商基础秒杀项目 (三) 通用的返回对象 & 异常处理
SpringBoot构建电商基础秒杀项目 学习笔记 定义通用的返回对象 public class CommonReturnType { // success, fail private String ...