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& ...
随机推荐
- mybatis的执行流程
1.SqlSessionFactoryBuilder与SqlSessionFactory 我们一般在使用mybatis是都会通过new SqlSessionFactoryBuilder.build(. ...
- leetcode-31-下一个排列
本题目在凌应标老师的<算法设计与分析>第八次作业中出现,可供参考. 题目描述: 实现获取下一个排列的函数,算法需要将给定数字序列重新排列成字典序中下一个更大的排列. 如果不存在下一个更大的 ...
- linux之getenv putenv setenv和unsetenv详解
1.getenv函数 头文件:#include<stdlib.h> 函数原型: char * getenv(const char* name); 函数说明:getenv()用来取得参数na ...
- app.module.ts说明
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; ...
- 【bug】记一个有趣的“bug”
产品经理在使用我们用户功能的是,需要查询一个用户,知道这个用户的id,我说支持模糊查询的. 他输入"余XX",点击查询,怎么都查不出这个用户. 我到用户表里确认,确实有这个ID的用 ...
- Camera Sensor
camera sensor分为YUV sensor和Bayer sensor. YUV Sensor YUV Sensor输出的格式是YUV,图像的处理效果使用sensor内部的ISP,BB端接收到的 ...
- Java中静态变量的声明位置
Java中静态变量只能是成员变量,局部方法中的局部变量除final外不能有任何其他修饰符,例如: public class Test { static String x = "1" ...
- Hibernate查询方式&抓取策略
Hibernate的查询方式 1.OID查询 hibernate根据对象的OID(主键)进行检索 使用get方法 Customer customer=session.get(Customer.clas ...
- xshell本地上传文件至服务器
今天本地写了个项目,想传到服务器部署起来.就上网百度了一下挺多的,一个个记录下,如有雷同,纯属抄袭. lrzsz方法 rz # 检查是否安装 yum -y install lrzsz # 安装 rpm ...
- Mac 10.12安装迅雷2.7.2
说明:主要是老版本难找,这个版本最好用. 下载: (链接: https://pan.baidu.com/s/1qXTldI8 密码: dmfe)