Claris and XOR
Claris loves bitwise operations very much, especially XOR, because it has many beautiful features. He gets four positive integers a,b,c,da,b,c,d that satisfies a\leq ba≤b and c\leq dc≤d. He wants to choose two integers x,yx,y that satisfies a\leq x\leq ba≤x≤b and c\leq y\leq dc≤y≤d, and maximize the value of x~XOR~yx XOR y. But he doesn't know how to do it, so please tell him the maximum value of x~XOR~yx XOR y.
The first line contains an integer T\left(1\leq T\leq10,000\right)T(1≤T≤10,000)——The number of the test cases. For each test case, the only line contains four integers a,b,c,d\left(1\leq a,b,c,d\leq10^{18}\right)a,b,c,d(1≤a,b,c,d≤1018). Between each two adjacent integers there is a white space separated.
For each test case, the only line contains a integer that is the maximum value of x~XOR~yx XOR y.
2
1 2 3 4
5 7 13 15
6
11
In the first test case, when and only when x=2,y=4x=2,y=4, the value of x~XOR~yx XOR y is the maximum. In the second test case, when and only when x=5,y=14x=5,y=14 or x=6,y=13x=6,y=13, the value of x~XOR~yx XOR y is the maximum.
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <queue>
using namespace std;
#define INF 0x3f3f3f3f
#define ll long long int const MAX = ;
int n; struct Trie
{
int root, tot, next[MAX][], end[MAX];
inline int node()
{
memset(next[tot], -, sizeof(next[tot]));
end[tot] = ;
return tot ++;
} inline void Init()
{
tot = ;
root = node();
} inline void insert(ll x)
{
int p = root;
for(int i = ; i >= ; i--)
{
int ID = (( << i) & x) ? : ;
if(next[p][ID] == -)
next[p][ID] = node();
p = next[p][ID];
}
end[p] = x;
} inline int search(int x)
{
int p = root;
for(int i = ; i >= ; i--)
{
int ID = (( << i) & x) ? : ;
if(ID == )
p = next[p][] != - ? next[p][] : next[p][];
else
p = next[p][] != - ? next[p][] : next[p][];
}
return x ^ end[p];
} }trie; int a[],b[];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n=;
int WTF = ,ans=, x;
trie.Init();
for(int i = ; i < ; i++)
{
scanf("%d", &a[i]);
}
for(int i = ; i < ; i++)
{
scanf("%d", &b[i]);
}
for(int i=a[]; i<=a[]; i++){
//WTF=0;
//trie.insert(1);
//WTF = WTFx(WTF, trie.search(1));
for(int j=b[]; j<=b[]; j++){
trie.Init();
trie.insert(i);
WTF = max(WTF, trie.search(i));
trie.insert(j);
WTF = max(WTF, trie.search(j));
ans=max(WTF,ans);
}
}
printf("%d\n", WTF);
}
}
Claris and XOR的更多相关文章
- BC之Claris and XOR
http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...
- hdu 5661 Claris and XOR
Claris and XOR Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- Claris and XOR(模拟)
Claris and XOR Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- HDU5661 Claris and XOR
我们求二进制是怎么求的呢:先看看二进制的每一位代表多大:.......32 16 8 4 2 1 假如n=10, ..... 32>n ,不要. 16>n,不要. 8<=n,要,然后 ...
- HDU 5661 Claris and XOR 贪心
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5661 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- 【整理】XOR:从陌生到头晕
一:解决XOR常用的方法: 在vjudge上面输入关键词xor,然后按照顺序刷了一些题. 然后大概悟出了一些的的套路: 常用的有贪心,主要是利用二进制的一些性质,即贪心最大值的尽量高位取1. 然后有前 ...
- bzoj4589 FWT xor版本
4589: Hard Nim Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 865 Solved: 484[Submit][Status][Disc ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
- 二分+DP+Trie HDOJ 5715 XOR 游戏
题目链接 XOR 游戏 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
随机推荐
- Caching-缓存架构与源码分析
Caching-缓存架构与源码分析 首先奉献caching的开源地址[微软源码] 1.工程架构 为了提高程序效率,我们经常将一些不频繁修改,但是使用了还很大的数据进行缓存.尤其是互联网产品,缓存可以说 ...
- C# WinForm多线程(二)ThreadPool 与 Timer
本文接上文,继续探讨WinForm中的多线程问题,再次主要探讨threadpool 和timer 一 ThreadPool 线程池(ThreadPool)是一种相对较简单的方法,它适应于一些需要多个 ...
- log4net使用特定的解释
说明:该程序演示如何使用log4net记录日志信息. log4net它是-known开源组件的日志记录功能.使用log4net可以很容易地将信息记录到文件.控制台.Windows事件日志和数据库(含有 ...
- 《数字图像处理原理与实践(MATLAB文本)》书代码Part7
这篇文章是<数字图像处理原理与实践(MATLAB文本)>一本书的代码系列Part7(由于调整先前宣布订单,请读者注意分页程序,而不仅仅是基于标题数的一系列文章),第一本书特色186经225 ...
- Unity判断网络连接类型
使用NetworkReachability判断手机游戏当前的网络连接类型,是wifi还是234G using UnityEngine; using System.Collections; public ...
- IBatis.Net获取执行的Sql语句
前言 IBatis.Net中Sql语句是些在配置文件中的,而且配置文件是在程序启动时读取的(我们开发的时候需要将其设置成较新复制或者是始终复制),而不是程序将其包含在其中(例如NHibernate的映 ...
- 2013成都邀请赛J称号||HDU4725 The Shortest Path in Nya Graph(spfa+slf最短的优化)
职务地址:HDU 4725 这题卡了好长时间了,建图倒是会建,可是不会最短路的算法优化,本以为都须要堆去优化的,打算学了堆之后再来优化.可是昨晚CF的一道题..(那题也是不优化过不了..)然后我就知道 ...
- [原创].NET 业务框架开发实战之八 业务层Mapping的选择策略
原文:[原创].NET 业务框架开发实战之八 业务层Mapping的选择策略 .NET 业务框架开发实战之八 业务层Mapping的选择策略 前言:在上一篇文章中提到了mapping,感觉很像在重新实 ...
- JFinal 的源代码超具体的分析DB+ActiveRecord
我记得有人告诉我."面试一下spring源代码.看ioc.aop源代码"那为什么要看这些开源框架的源代码呢,事实上非常多人都是"应急式"的去读.就像读一篇文章一 ...
- python在windows通过安装模块错误
我的环境是win7+vs2013+python3.2,他们是32地点 windows通过安装模块错误 1)Unable to find vcvarsall.bat : 打开"<pyth ...