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& ...
随机推荐
- Machine learning 第5周编程作业
1.Sigmoid Gradient function g = sigmoidGradient(z) %SIGMOIDGRADIENT returns the gradient of the sigm ...
- orcal创建序列
CREATE SEQUENCE flowjobseq --序列名INCREMENT BY 1 -- 每次加几个 START WITH 2000 -- 从1开始计数 NOMAXVALUE -- 不设置最 ...
- pygame学习_part1_pygame写程序前的准备工作
import pygame from pygame import * pygame.init() #准备pygame,不准备无法使用功能 pygame.display.set_mode((x,y坐标) ...
- Web安全之CSRF攻击的防御措施
Web安全之CSRF攻击的防御措施 CSRF是什么? Cross Site Request Forgery,中文是:跨站点请求伪造. CSRF攻击者在用户已经登录目标网站之后,诱使用户访问一个攻击 ...
- Mac下一台电脑管理多个SSH KEY(转)
一.关于ssh是什么? http://www.ruanyifeng.com/blog/2011/12/ssh_remote_login.html 二.需求: 一台电脑上(Mac os)管理多个ssh ...
- ElasticSearch 问题分析:No data nodes with HTTP-enabled available
环境:ES-5.4.0版本,部署方式:3master node+2client node+3data node 说明:data node和client node都配置了http.enabled: fa ...
- mp3转speex的一些研究(貌似不能播放,暂存着)
思路是,先从mp3中提取pcm(raw原始数据),再将原始数据转成speex. 貌似不能播放,可能还存在其他问题,需要继续研究. 使用了两个类库NSpeex和NAudio using (var wav ...
- JavaScript设计模式-21.命令模式
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- linux mint19 解决docker必须使用sudo问题
1 安装完docker 使用时,提示权限不够 ~$ docker info Got permission denied while trying to connect to the Docker da ...
- log4php0.9的详细配备实例说明
一.什么是log4php: log4j在JAVA中可算是大名鼎鼎的日志开发包了,它为apche组织维护项目,VxR兄使用php来实现了log4j的功能, 目前log4php已经作为log4j的一个子项 ...