Codeforces.1088D.Ehab and another another xor problem(交互 思路)
边颓边写了半上午A掉啦233(本来就是被无数人过掉的好吗→_→)
首先可以\(Query\)一次得到\(a,b\)的大小关系(\(c=d=0\))。
然后发现我们是可以逐位比较出\(a,b\)在这每位上的大小关系的。
最后还剩下\(a,b\)相等的位需要再判断是\(0\)还是\(1\),\(a,b\)分别异或一个\(1,0\)就可以了(假如都是\(0,0\),那异或之后\(1,0\)是\(a>b\);如果都是\(1,1\),异或之后就是\(0,1\),\(a<b\))。
询问次数\(61\)。
//30ms 0KB
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
#define Flush() fflush(stdout)
#define BIT 29
typedef long long LL;
const int N=35;
int vis[N];
inline int read()
{
int now=0,f=1;register char c=gc();
for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
for(;isdigit(c);now=now*10+c-48,c=gc());
return now*f;
}
int Query(int c,int d)
{
printf("? %d %d\n",c,d), Flush();
return read();
}
void Equal(int &a,int &b,int c,int d)
{
for(int i=BIT; ~i; --i)
if(!vis[i])
if(Query(c|(1<<i),d)==-1) a|=1<<i, b|=1<<i;
}
void Solve(int &a,int &b)
{//f=1:a>b
a=0,b=0;
int c=0,d=0,res=Query(0,0),f=res==1;
if(!res) {Equal(a,b,0,0); return;}
for(int i=BIT; ~i; --i)
{
res=Query(c|(1<<i),d|(1<<i));
if((f&&res==-1)||(!f&&res==1))
{
vis[i]=1;
if(f) c|=1<<i, a|=1<<i;
else d|=1<<i, b|=1<<i;
if(!(res=Query(c,d))) {Equal(a,b,c,d); return;}
f=res==1;
}
}
Equal(a,b,c,d);
}
int main()
{
int a,b; Solve(a,b);
printf("! %d %d\n",a,b), Flush();
return 0;
}
Codeforces.1088D.Ehab and another another xor problem(交互 思路)的更多相关文章
- codeforces#1157D. Ehab and the Expected XOR Problem(构造)
题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...
- 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 1088E Ehab and a component choosing problem
Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ 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 Round #525 (Div. 2) D. Ehab and another another xor problem(交互题 异或)
题目 题意: 0≤a,b<2^30, 最多猜62次. 交互题,题目设定好a,b的值,要你去猜.要你通过输入 c d : 如果 a^c < b^d ,会反馈 -1 : 如果 a^c = b^ ...
- 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 1174C Ehab and a Special Coloring Problem
题目链接:http://codeforces.com/problemset/problem/1174/C 题意:给你一个n,要你填充 下标由2 ~ n 的数组ai,要求下标互质的俩个数不能相等,并且数 ...
- 【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,每次你可以给定c,d询问a xor c和b xor d的大小关系,最多询问62次($a,b<=2^{30}$),问a和b 考虑从高位往低位做,正在做第i位,已经知道了a和b的 ...
随机推荐
- Tensorflow 损失函数及学习率的四种改变形式
Reference: https://blog.csdn.net/marsjhao/article/details/72630147 分类问题损失函数-交叉熵(crossentropy) 交叉熵描述的 ...
- Centos7上实现不同网段的服务器文件共享
目的:实现不同网段的服务器实现文件共享 前提:服务器1可以和共享服务器互通,共享服务器和服务器2互通 拓扑如下: 思路: 一般文件共享有涉及windown系统的用samba,纯类centos系统就用n ...
- 【C++ Primer 第13章】1. 拷贝控制、赋值和销毁
拷贝控制.赋值和销毁 如果一个构造函数的第一个参数是自身类的引用,且额外的参数都有默认值,则此构造函数是拷贝控制函数(拷贝构造函数不应该是explicit的). 如果我们没有为一个类定义拷贝构造函数, ...
- unable to access android sdk add-on list(转)
造成这个问题的原因可能有多种,下面两种方法,我亲自测试后可用,如果都不行,请在评论里告诉我,我会尽快帮你分析解决.左侧的文章分类中,Android Studio编译构建错误记录了我开发中遇到的所有编译 ...
- MySQL主从备份配置实例
转载自:https://www.cnblogs.com/ahaii/p/6307648.html MySQL主从备份配置实例 场景: 1.主服务器192.168.0.225.从服务器192.168.0 ...
- 利用 Windows API Code Pack 修改音乐的 ID3 信息
朋友由于抠门 SD 卡买小了,结果音乐太多放不下,又不舍得再买新卡,不得已决定重新转码,把音乐码率压低一点,牺牲点音质来换空间(用某些人的话说,反正不是搞音乐的,听不出差别)… 结果千千静听(百度音乐 ...
- (转载)dotnet core 中文乱码 codepages
引子 转载自:http://www.jianshu.com/p/1c9c59c5749a 参考:.Net Core 控制台输出中文乱码 上文中我查阅了一些cli的源码, 闲来无事就继续翻代码, 冥冥之 ...
- nginx proxy_pass指令’/’注意事项
1. proxy_pass配置说明 不带/ location /test/ { proxy_pass http://t6:8300; } 带/ location /test/ { proxy_pass ...
- Storm——Android SQLite数据库管理类库
Storm是一个Android SQLite数据库管理类库,可以通过注解创建表和迁移数据库.它不是ORM框架. 特性: 1.通过@Annotations创建表: 2.通过@Annotations迁 ...
- WPF中矢量图制作和引用
WPF程序有时需要适配不同大小的屏幕,图片是像素图的话,拉伸之后会变模糊,影响美观度,因此可以考虑使用矢量图.网上找到了相应的介绍:http://learnwpf.com/post/2006/06/0 ...