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^d ,会反馈 0 ;
如果 a^c > b^d ,会反馈 1 ;
每次猜前面都用 ? 表示, 最后一行用!表示已经知道a b的值。
思路:
不会,然后去找别人博客学。 大致思路就是:a b都是二进制来表示,从高到低位 把a和b的每一位都判断出来。
判断a b同一位是否相等:
1. 如果相等,判断这一位是0 还是 1 ,
判断方法是:printf("? %d %d\n", a|(1<<i),b);
scanf("%d",&now); now是反馈
如果now是1,则a b 的这一位都是1(a=a|(1<<i), b=b|(1<<i) )
2. 如果不等,判断 a这一位是1 && b这一位是0 还是 a这一位是0 && b这一位是1 ,
判断方法是:见代码
步骤:
一开始通过c=0 d=0 判断a b的相对大小:
1. 如果a==b,说明a和b的所有二进制位都是相同的,按上面的1进行解决;
2. 如果a !=b,说明a b存在某些二进制位不相同的情况,所以:
首先判断当前位是否相等,如果相等,按上面1的做法 ; 如果不相等,按上面2的做法。
再判断 当前位以后的所有位 是否全都相同,如果相同,进入此1,如果不相同,进入此2.
#include<iostream>
#include<cstdio>
#include <cctype>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<cmath>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
#define mem(a,x) memset(a,x,sizeof(a))
#define se second
#define fi first
const ll mod=1e9+;
const int INF= 0x3f3f3f3f;
const int N=1e5; int main()
{
int a=,b=,fb,now;
printf("? 0 0\n");
fflush(stdout);
scanf("%d",&fb); for(int i=;i>=;i--)
{
if(fb==)//a b 在当前i位以后的 所有都相同
{
printf("? %d %d\n",a|(<<i),b);
fflush(stdout);
scanf("%d",&now); //判断当前这位是1还是0
if(now==-) //是1
a=a|(<<i), b=b|(<<i);
}
else//a b 在当前i位以后的各位 存在不同
{
printf("? %d %d\n",a|(<<i),b|(<<i));//判断当前位是否相同
fflush(stdout);
scanf("%d",&now);
if(now==fb) //这一位的改变不影响ab之间谁大谁小,所以是相同的
{
printf("? %d %d\n",a|(<<i),b);
fflush(stdout);
scanf("%d",&now); //判断这位是1还是0
if(now==-) //是1
a=a|(<<i), b=b|(<<i);
}
else // a中的这一位和b中的这一位 不相同
{
//假设答案a为101,b为001,代码中a=0,b=0,
//所以a|(1<<2)=100,b|(1<<2)=100, 101^100=001,001^100=101,
//此时now==-1,说明a这位为1,b这位为0; //如果答案b为101,a为001,代码中a=0,b=0,
//所以a|(1<<2)=100,b|(1<<2)=100,001^100=101,101^100=001,
//此时now==1,说明a这位为0,b这位为1;
if (now==-) a |= << i;
else if(now==) b |= << i; //因为now不可能=0了 printf("? %d %d\n",a,b);
//这一位判断完毕,接着算a b在这位以后所有的是不是相同
fflush(stdout);
scanf("%d",&fb);
}
}
}
printf("! %d %d\n", a, b);
fflush(stdout);
}
Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(交互题 异或)的更多相关文章
- 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 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)E. Ehab and a component choosing problem
E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个 ...
- Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学
题意:给出树 求最大的sigma(a)/k k是选取的联通快个数 联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值 这里先要满足最大平均值 而首先要满足最大 也就是一个数的时候可 ...
- Codeforces Round #525 (Div. 2) F. Ehab and a weird weight formula
F. Ehab and a weird weight formula 题目链接:https://codeforces.com/contest/1088/problem/F 题意: 给出一颗点有权值的树 ...
- Codeforces Round #525 (Div. 2)B. Ehab and subtraction
B. Ehab and subtraction 题目链接:https://codeforc.es/contest/1088/problem/B 题意: 给出n个数,给出k次操作,然后每次操作把所有数减 ...
- Codeforces Round #525 (Div. 2)A. Ehab and another construction problem
A. Ehab and another construction problem 题目链接:https://codeforc.es/contest/1088/problem/A 题意: 给出一个x,找 ...
- Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task 数学 mod运算的性质
C. Ehab and a 2-operation task 数学 mod运算的性质 题意: 有两种对前缀的运算 1.对前缀每一个\(a +x\) 2.对前缀每一个\(a\mod(x)\) 其中x任选 ...
- Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task
传送门 https://www.cnblogs.com/violet-acmer/p/10068786.html 题意: 给定一个长度为 n 的数组a[ ],并且有两种操作: ①将前 i 个数全都加上 ...
随机推荐
- C# .NET UDP 形式调用 graylog,gelf
-- 发送: GelfLogModel m = new GelfLogModel(); m.version = "1.1"; m.host = "128.0.14.39& ...
- RabbitMQ官方教程三 Publish/Subscribe(GOLANG语言实现)
RabbitMQ官方教程三 Publish/Subscribe(GOLANG语言实现) 在上一个教程中,我们创建了一个工作队列. 工作队列背后的假设是,每个任务都恰好交付给一个worker处理. 在这 ...
- SpringBoot里自定义banner
国外有一个专门用来生成banner的网址:http://patorjk.com/software/taag ,打开这个网址,生成你想要的字儿. 生成时,我们可以选择自己喜欢的字体等信息. 完成后,选择 ...
- C++ 枚举定义
我们在平常的编程中,时常需要为一些属性定义一组可以选择的值,比如文件打开的状态可能会有三种:输入 输出和追加 我们一般情况下记录这些状态是让每一个状态和一个常数相对应 比如 ; ; ; 这个方法虽 ...
- js禁止退出当前页面
禁止用户退出网页,就一个添加窗体历史状态方法,代码很简单,但是建议大家不要去使用,会给用户带来不友好的体验,我这里只是学习这种方法,看到自己代码上有也知道在哪里改变这些代码,所以分享一下: 实现原理: ...
- date.toLocaleString()的替换
Date date = new Date(); System.out.println("前:" + date.toLocaleString()); SimpleDateFormat ...
- 基因id转换
DAVID网站提供了id转换的功能 1 选择上传gene list文件 2 选择上传ID的类型,我们ID-list.txt中的是Ensembl Gene ID,所以这里选ENSEMBL_GENE_ID ...
- 在linux上cuda9.0 cudnn7.* 安装python3.6 tensorflow 1.5.1
链接:https://www.jianshu.com/p/bcf37d0e4e9b 为了入门机器学习的小伙伴能安装好工具,特制作此教程 按照 Anaconda 下载网站上的说明下载并安装 Anacon ...
- FZU2018级算法第五次作业 missile(排序+枚举)
在解题报告之前,首先对同一次作业中另外一题(求逆序对)某人在未经冰少允许情况下,擅自登录冰少账号,原模原样剽窃冰少代码,并且最终还被评为优秀作业的行为表示严正抗议! 题目大意: 二维平面上给出 n 个 ...
- nginx 二级目录高级写法
nginx二级目录高级配置: location ~ .*\.(html)$ { expires 1m; error_page 404 = /test/index.html; access_log /d ...