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& ...
随机推荐
- Xcode括号自动补全以及二次编译后不显示输入
今天遇到了一个大坑,在使用栈来进行计算表达式的时候,发现输入括号就报错,以及二次编译后不显示. 测试了好久,经过无数次debug后. 二次编译不显示还是没搞明白,不过输入倒是没什么问题,就是不显示出来 ...
- Nodejs统计每秒记录日志数
问题:线上的写日志操作非常频繁,想统计每秒写了多少行数据?假如没法送一个消息写一个日志,问题也就变成了,每秒发送多少消息了. 日志采用log4js书写,格式如下: [-- ::33.548] [INF ...
- FlowPortal-BPM——文件目录功能
安装目录文件夹:Attachments 附件bin Bin目录:dll文件的引用DataSourceProviders 固定的数据库连接文件ExtServer 数据源服务FormService 表单服 ...
- 【性能测试】脚本开发,最普通的http协议脚本
放上来做个备份: Action() { double transTime; // 事务消耗时间 lr_start_transaction("营销_01_MSMH0011_查询拥有码列表&qu ...
- follow up2-20190426
406. Minimum Size Subarray 同向双指针 https://www.lintcode.com/problem/minimum-size-subarray-sum/descript ...
- Mac使用Launchd命令行lauchctl操作服务的简单用法
注意:操作时前面比如带上sudo,不然只能操作当前用户的服务,会出现无法操作一些root用户的服务的问题.系统版本为Mac 10.12. 1.配置好plist之后: #加载一个服务到启动列表 sudo ...
- 【es6】js原生的promise
JavaScript 是单线程的,这意味着任何两句代码都不能同时运行,它们得一个接一个来.在浏览器中,JavaScript 和其他任务共享一个线程,不同的浏览器略有差异,但大体上这些和 JavaScr ...
- JavaScript数据结构-18.图结构广度优先和最短路径
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- JavaScript数据结构-5.队列
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 数据库分库分表(一)常见分布式主键ID生成策略
主键生成策略 系统唯一ID是我们在设计一个系统的时候常常会遇见的问题,下面介绍一些常见的ID生成策略. Sequence ID UUID GUID COMB Snowflake 最开始的自增ID为了实 ...