cf1088D. Ehab and another another xor problem(思维)
题意
系统中有两个数\((a, b)\),请使用\(62\)以内次询问来确定出\((a, b)\)
每次可以询问两个数\((c, d)\)
若\(a \oplus c > b \oplus d\)返回\(1\)
若\(a \oplus c = b \oplus d\)返回\(0\)
若\(a \oplus c < b \oplus d\)返回\(-1\)
保证/需要保证\(0 \leqslant a, b, c, d, < 2^{30}\)
Sol
严重怀疑自己小学数学没学好,刚开始以为\(a, b, c, d < 2^{30}\)说明每位只有两次机会,然后模拟了\(4 * 4 * 3\)种情况后发现怎么都搞不了,今天看std发现是每位询问两次后还有额外的两次询问机会qwqqqqq
如果多两次机会的话就能搞了,因为我打比赛的时候遇到的问题就是如何确定出当前两位和除去这两位之后的大小关系。这样我们可以上来先询问出\((a, b)\)的大小关系,然后xjb特判一下。。
标算好神仙啊。。
#include<bits/stdc++.h>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long
#define LL long long
#define rg register
#define pt(x) printf("%d ", x);
#define Fin(x) {freopen(#x".in","r",stdin);}
#define Fout(x) {freopen(#x".out","w",stdout);}
using namespace std;
const int MAXN = 1e6 + 10, INF = 1e9 + 10, mod = 1e9 + 7;
const double eps = 1e-9;
int Query(int c, int d) {
printf("? %d %d\n", c, d); fflush(stdout);
int opt; scanf("%d", &opt); return opt;
}
int a, b, flag, B = 29;
main() {
flag = Query(0, 0);
for(int i = B; i >= 0; i--) {
int x = Query(a | (1 << i), b), y = Query(a, b | (1 << i));
if(x == y) {
if(flag == 1) a |= (1 << i);
else b |= (1 << i);
flag = x;
} else if(x == -1) {
a |= (1 << i);
b |= (1 << i);
}
}
printf("! %d %d", a, b);
return 0;
}
cf1088D. Ehab and another another xor problem(思维)的更多相关文章
- 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的 ...
- CF1088D Ehab and another another xor problem
思路: 根据异或的性质一位一位来搞.参考了https://blog.lucien.ink/archives/362/ 实现: #include <bits/stdc++.h> using ...
- 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 ...
- 【CF1174D】 Ehab and the Expected XOR Problem - 构造
题面 Given two integers \(n\) and \(x\), construct an array that satisfies the following conditions: · ...
- CF D. Ehab and the Expected XOR Problem 贪心+位运算
题中只有两个条件:任意区间异或值不等于0或m. 如果只考虑区间异或值不等于 0,则任意两个前缀异或值不能相等. 而除了不能相等之外,还需保证不能出现任意两个前缀异或值不等于m. 即 $xor[i]$^ ...
- 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(待完成)
参考资料: [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\ ...
- CF1174D Ehab and the Expected XOR Problem
思路: 使用前缀和技巧进行问题转化:原数组的任意子串的异或值不能等于0或x,可以转化成前缀异或数组的任意两个元素的异或值不能等于0或x. 实现: #include <bits/stdc++.h& ...
随机推荐
- datetime之 utcnow 和now的用法
from datetime import datetime print(datetime.now()) 本地时间 print(datetime.utcnow()) 国际时间
- (五)Audio子系统之AudioRecord.stop
在上一篇文章<(四)Audio子系统之AudioRecord.read>中已经介绍了AudioRecord如何获取音频数据,接下来,继续分析AudioRecord方法中的stop的实现 函 ...
- dubbo学习笔记:快速搭建
搭建一个简单的dubbo服务 参考地址: dubbo官网:http://dubbo.apache.org/zh-cn/docs/user/references/registry/zookeeper.h ...
- 通过view实现字段的只读、隐藏操作【转】
原文地址:http://cn.openerp.cn/view_groups/ 在OpenERP V7视图(ir.ui.view)多了一个非常有用的字段(groups_id) 'groups_id': ...
- OpenERP 中国财务模块 调整
最开始的模样是这个样子的 后三行是没用的,于是在RML文件中注释掉相关的代码,改进后的界面如下: 这个样子看起来是好多了,但是 数量跟是十亿千百的那块看起来还是很别扭,调整行高后的结果: 最诡异的事情 ...
- python并发学习总结
目录 一.理解操作系统 二.任务类型 三.Socket模块 四.一个简单的C/S程序 五.使用阻塞IO实现并发 方案一:阻塞IO+多进程 方案二:阻塞IO+多线程 阻塞IO模型的思考和总结 六.使用非 ...
- WCF系列教程之WCF客户端调用服务
1.创建WCF客户端应用程序需要执行下列步骤 (1).获取服务终结点的服务协定.绑定以及地址信息 (2).使用该信息创建WCF客户端 (3).调用操作 (4).关闭WCF客户端对象 二.操作实例 1. ...
- JS框架设计之命名空间设计一种子模块
命名空间 1.种子模块作为一个框架的最开始,除了负责初始化框架的最基础部分. 2.种子模块作为框架的最开始,那么什么是种子框架的最开始呢?答案是IIFE(立即调用函数表达式); IIFE(立即调用函数 ...
- 再学C/C++ 之 指针常量 和 常量指针
(1)指针常量,将指针的指向当成常量.即指针变量的值只能在定义的时候初始化,定义后不能修改,也就是说不能改变指针变量的指向.但是不影响所指对象的访问特征.其定义形式为: 类型 * const 指针 / ...
- 【数组】Unique Paths II
题目: Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. H ...