题目链接

边颓边写了半上午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\)。

  1. //30ms 0KB
  2. #include <cstdio>
  3. #include <cctype>
  4. #include <algorithm>
  5. #define gc() getchar()
  6. #define Flush() fflush(stdout)
  7. #define BIT 29
  8. typedef long long LL;
  9. const int N=35;
  10. int vis[N];
  11. inline int read()
  12. {
  13. int now=0,f=1;register char c=gc();
  14. for(;!isdigit(c);c=='-'&&(f=-1),c=gc());
  15. for(;isdigit(c);now=now*10+c-48,c=gc());
  16. return now*f;
  17. }
  18. int Query(int c,int d)
  19. {
  20. printf("? %d %d\n",c,d), Flush();
  21. return read();
  22. }
  23. void Equal(int &a,int &b,int c,int d)
  24. {
  25. for(int i=BIT; ~i; --i)
  26. if(!vis[i])
  27. if(Query(c|(1<<i),d)==-1) a|=1<<i, b|=1<<i;
  28. }
  29. void Solve(int &a,int &b)
  30. {//f=1:a>b
  31. a=0,b=0;
  32. int c=0,d=0,res=Query(0,0),f=res==1;
  33. if(!res) {Equal(a,b,0,0); return;}
  34. for(int i=BIT; ~i; --i)
  35. {
  36. res=Query(c|(1<<i),d|(1<<i));
  37. if((f&&res==-1)||(!f&&res==1))
  38. {
  39. vis[i]=1;
  40. if(f) c|=1<<i, a|=1<<i;
  41. else d|=1<<i, b|=1<<i;
  42. if(!(res=Query(c,d))) {Equal(a,b,c,d); return;}
  43. f=res==1;
  44. }
  45. }
  46. Equal(a,b,c,d);
  47. }
  48. int main()
  49. {
  50. int a,b; Solve(a,b);
  51. printf("! %d %d\n",a,b), Flush();
  52. return 0;
  53. }

Codeforces.1088D.Ehab and another another xor problem(交互 思路)的更多相关文章

  1. codeforces#1157D. Ehab and the Expected XOR Problem(构造)

    题目链接: http://codeforces.com/contest/1174/problem/D 题意: 构造一个序列,满足以下条件 他的所有子段的异或值不等于$x$ $1 \le a_i< ...

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

  3. Codeforces 1088E Ehab and a component choosing problem

    Ehab and a component choosing problem 如果有多个连接件那么这几个连接件一定是一样大的, 所以我们先找到值最大的连通块这个肯定是分数的答案. dp[ i ]表示对于 ...

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

  5. 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^ ...

  6. 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 的相对大小 ...

  7. Codeforces 1174C Ehab and a Special Coloring Problem

    题目链接:http://codeforces.com/problemset/problem/1174/C 题意:给你一个n,要你填充 下标由2 ~ n 的数组ai,要求下标互质的俩个数不能相等,并且数 ...

  8. 【CF1174D】 Ehab and the Expected XOR Problem - 构造

    题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...

  9. 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的 ...

随机推荐

  1. day4-list,列表

    dist: 增:1.append(obj),在列表最后添加元素: 2.insert(index,object),在索引处添加元素: 3.extend,迭代添加元素,所添加元素必须可迭代. 删:1.po ...

  2. js中json对象数组按对象属性排序---1

    转载:https://www.cnblogs.com/jasonwang2y60/p/6656103.html 在实际工作经常会出现这样一个问题:后台返回一个数组中有i个json数据,需要我们根据js ...

  3. Canvas锯齿问题

    canvas的宽高必须通过HTML属性指定,不能通过CSS指定,否则会有锯齿 这个是通过CSS定义宽高,绘制的图形 #myCanvas{ background: black; height: 800p ...

  4. html5页面调用手机打电话功能

    <head>里面加上:<meta name="format-detection" content="telephone=yes"/> 需 ...

  5. windows下KafkaOffsetMonitor下载及安装

    KafkaOffsetMonitor是一个可视化工具的jar包,如KafkaOffsetMonitor-assembly-0.2.1.jar,用来来监控kafka的使用状态. 一.下载地址 https ...

  6. win10ssh连接ubuntu服务器并本地绘图

    update @ 2018-11-07 00:36:38 用xrdp+tigervnc等的组合,可以使用原生unity桌面.具体教程见ubuntu日常使用指南 工具准备 win10上: xshell, ...

  7. Git基础(三) 跟踪文件

    检查当前文件状态 git status 跟踪新文件 git add README 状态简览 git status -s 或 git status --short 忽略文件 创建一个名为.gitigno ...

  8. webpack学习笔记--多种配置类型

    除了通过导出一个 Object 来描述 Webpack 所需的配置外,还有其它更灵活的方式,以简化不同场景的配置. 下面来一一介绍它们. 导出一个 Function 在大多数时候你需要从同一份源代码中 ...

  9. Codeforces 865C Gotta Go Fast 二分 + 期望dp (看题解)

    第一次看到这种骚东西, 期望还能二分的啊??? 因为存在重置的操作, 所以我们再dp的过程中有环存在. 为了消除环的影响, 我们二分dp[ 0 ][ 0 ]的值, 与通过dp得出的dp[ 0 ][ 0 ...

  10. Codeforces 316G3 Good Substrings 字符串 SAM

    原文链接http://www.cnblogs.com/zhouzhendong/p/9010851.html 题目传送门 - Codeforces 316G3 题意 给定一个母串$s$,问母串$s$有 ...