Claris and XOR

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 744    Accepted Submission(s): 330

Problem Description
Claris loves bitwise operations very much, especially XOR, because it has many beautiful features. He gets four positive integers a,b,c,d that satisfies a≤b and c≤d. He wants to choose two integers x,y that satisfies a≤x≤b and c≤y≤d, and maximize the value of x XOR y. But he doesn't know how to do it, so please tell him the maximum value of x XOR y.
 
Input
The first line contains an integer 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(1≤a,b,c,d≤1018). Between each two adjacent integers there is a white space separated.
 
Output
For each test case, the only line contains a integer that is the maximum value of x XOR y.
 
Sample Input
2
1 2 3 4
5 7 13 15
 
Sample Output
6
11

Hint

In the first test case, when and only when $x=2,y=4$, the value of $x~XOR~y$ is the maximum.
In the second test case, when and only when $x=5,y=14$ or $x=6,y=13$, the value of $x~XOR~y$ is the maximum.

 

数据范围是10^18,转化为二进制是2^62左右,检查每一位的取值
1.如果只能取1那就取
2.如果可以取1或者取零那么就让x,y中的一方取0,另一方取1

#include <cstdio>
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
long long a,b,c,d;
scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
long long ans,ansx=,ansy=;
for(int i=;i>=;i--)
{
ans=1LL<<i;
if(ansx+ans<=b&&ansy+ans<=d)
{
if((ansx+ans<a)||(ansy+ans<c)) //必选,不然无法出现在范围内
{
if(ansx+ans<a) ansx+=ans;
if(ansy+ans<c) ansy+=ans;
}
else
{
ansx+=ans; //可选其中之一
}
}
else
{
if(ansx+ans<=b) ansx+=ans;
else if(ansy+ans<=d) ansy+=ans;
}
}
printf("%lld\n",ansx^ansy);
}
return ;
}

hdu 5661 Claris and XOR的更多相关文章

  1. HDU 5661 Claris and XOR 贪心

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5661 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  2. BC之Claris and XOR

    http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...

  3. Claris and XOR(模拟)

    Claris and XOR Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  4. Claris and XOR

    Problem Description Claris loves bitwise operations very much, especially XOR, because it has many b ...

  5. HDU5661 Claris and XOR

    我们求二进制是怎么求的呢:先看看二进制的每一位代表多大:.......32 16 8 4 2 1 假如n=10, ..... 32>n ,不要. 16>n,不要. 8<=n,要,然后 ...

  6. HDU 5683 zxa and xor 暴力模拟

    zxa and xor 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5683 Description zxa had a great interes ...

  7. HDU 5269 ZYB loves Xor I Trie树

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5269 bc:http://bestcoder.hdu.edu.cn/contests/con ...

  8. hdu 5269 ZYB loves Xor I

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission( ...

  9. bestcoder r44 p3 hdu 5270 ZYB loves Xor II

    这是昨晚队友跟我说的题,不知道当时是什么玄幻的事件发生了,,我看成了两两相乘的XOR 纠结了好长时间间 不知道该怎么办 今天早上看了下这道题,发现是两两相加的XOR  然后就想了想昨晚的思路 发现可做 ...

随机推荐

  1. Xcode8不能使用快捷键“command+/”注释代码的解决方法

    sudo /usr/libexec/xpccachectl 打开终端,输入该命令(如果电脑有密码的话,会有提示让输入密码) 接下来重启电脑. command + option + / 还可以多行注释

  2. NHibernate 映射失败 is not mapped

    1 区分大小写(实体类名) 2 MAP的XML设置为嵌入的资源 3 hibernate.cfg.xml配置添加map的程序集<mapping assembly="Model" ...

  3. 判断当前VC是不是正在展示的活跃页面

    viewController.isViewLoaded && viewController.view.window

  4. java web(spring mvc) 获取请求host 和 如何获取静态页的相对路径

    1.获取请求host StringBuffer url = request.getRequestURL(); String tempContextUrl = url.delete(url.length ...

  5. Unity 之 Shader 对Z深度的偏移

    对Z深度的偏移 Offset 指令给了我们一个操作正常的ZTest 检测结果的手段. Offset有两个参数,这两个参数理解起来不是很直观,而且具体实现是和硬件相关的 下面在实际例子中看他的效果 Sh ...

  6. SqlServer2008 无法修改表,超时时间已到 在操作完成之前超时解决方法

    在 SQL Server Management Studio 里, 通过菜单“工具-选项”打开选项对话框. 在左侧寻找“设计器-表设计器和数据库设计器”, 然后在右侧勾选“为表设计器更新重写连接字符串 ...

  7. 操作系统win2003 x64的,安装OFFICE2003后,DCOM服务找不到 WORD应用程序服务

    打开注册表,找到以下健值 HKEY_CLASSES_ROOT\AppID\{00020906-0000-0000-C000-000000000046} HKEY_CLASSES_ROOT\CLSID\ ...

  8. B-Tree 学习

    算法导论 第18章 B树与其他树的结构不同的是  B数是多叉而不是二叉树 而且分叉因子很大一般使用于数据库 针对需要硬盘IO的情况而使用 可以降低磁盘IOB树的一个节点是以磁盘的页面为单位,而不是数据 ...

  9. adv联系题

    http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html(新)

  10. C# 模拟上传图片

    上传图片的格式一定要按规定的写,不然没办法正确上传的. 我在上传的时候就是值前面没有空一行,导致上传不成功,很纠结的错误. 我要模拟的是一个FLASH的上传控件,我开始用HttpAnalyze抓包是抓 ...