题目

题意:

  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(交互题 异或)的更多相关文章

  1. 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 ...

  2. 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/ ...

  3. 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 题意: 给出一个 ...

  4. Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学

    题意:给出树 求最大的sigma(a)/k k是选取的联通快个数   联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值  这里先要满足最大平均值  而首先要满足最大  也就是一个数的时候可 ...

  5. 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 题意: 给出一颗点有权值的树 ...

  6. Codeforces Round #525 (Div. 2)B. Ehab and subtraction

    B. Ehab and subtraction 题目链接:https://codeforc.es/contest/1088/problem/B 题意: 给出n个数,给出k次操作,然后每次操作把所有数减 ...

  7. 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,找 ...

  8. 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任选 ...

  9. Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task

    传送门 https://www.cnblogs.com/violet-acmer/p/10068786.html 题意: 给定一个长度为 n 的数组a[ ],并且有两种操作: ①将前 i 个数全都加上 ...

随机推荐

  1. LeetCode:打印零与奇偶数【1116】

    LeetCode:打印零与奇偶数[1116] 题目描述 假设有这么一个类: class ZeroEvenOdd { public ZeroEvenOdd(int n) { ... } // 构造函数 ...

  2. 17、vue-cli3 js项目中引入ts混用(typeScript)

    说明: vue3.0搭建的项目,不过没有引入ts,后来需要用到一个插件是用ts写的,所以vue要用到ts... 一.安装typescript及loader npm install typescript ...

  3. IOPS 测试工具 FIO

    FIO是测试IOPS的非常好的工具,用来对硬件进行压力测试和验证,支持13种不同的I/O引擎. fio-2.8下载: wget http://brick.kernel.dk/snaps/fio-2.8 ...

  4. UN Report: Last 10 Years Likely the Hottest Decade on Record——VOA慢速英语

    听力地址:UN Report: Last 10 Years Likely the Hottest Decade on Record 中英对照:联合国报告称过去十年可能是有记录以来最热的十年 Words ...

  5. Spark 基础操作

    1. Spark 基础 2. Spark Core 3. Spark SQL 4. Spark Streaming 5. Spark 内核机制 6. Spark 性能调优 1. Spark 基础 1. ...

  6. webpack package code into different bundle

    Demo4操作手册 本Demo演示如何进行分块打包等较高级的使用 准备环境 初始化环境, cd到demo1目录之后, 执行如下命令: npm init -y npm install webpack w ...

  7. Python 数据处理库pandas教程(最后附上pandas_datareader使用实例)

    0 简单介绍 pandas是一个Python语言的软件包,在我们使用Python语言进行机器学习编程的时候,这是一个非常常用的基础编程库.本文是对它的一个入门教程. pandas提供了快速,灵活和富有 ...

  8. Tomcat部分知识点小结

    * Tomcat:web服务器软件     1. 下载:http://tomcat.apache.org/    2. 安装:解压压缩包即可. * 注意:安装目录建议不要有中文和空格    3. 卸载 ...

  9. 使用uiautomator 截图

    1)PC与移动设备建立连接. 2)找到ADB的安装路径,双击启动uiautomator. 路径:D:\ProgramFiles\adt-bundle-windows-x86_64-20140702\a ...

  10. ubuntu 安装 Java 开发环境

    可以使用命令 -jre-headless 或者使用:   本文链接:https://blog.csdn.net/sangewuxie/article/details/80958611 本人的ubunt ...