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. python之socket 网络编程

    提到网络通信不得不复习下osi七层模型: 七层模型,亦称OSI(Open System Interconnection)参考模型,是参考模型是国际标准化组织(ISO)制定的一个用于计算机或通信系统间互 ...

  2. Java数据类型转换

    一.Date与String相互转换 1.Date转换成String SimpleDateFormat dd = new SimpleDateFormat("yyyy-MM-dd HH:mm& ...

  3. 发送短信MFMessageComposeViewController

    if([MFMessageComposeViewController canSendText]) { MFMessageComposeViewController * controller = [[M ...

  4. 【openresty】向lua代码中传递参数

    前面介绍FormInputNginxModule模块时,明白了openresty如何获取post提交的数据. 然后,如果需要通过lua处理这些数据,需要把数据作为参数传递到lua中,lua获取了这些数 ...

  5. js+cookie 购物车

    $(function () { //var ctx = new Ch(); //ctx.Clear(); //$.cookie(ctx.cookieName, ""); //ale ...

  6. Java线程池入门

    序 为什么要用线程池?什么情况下才会用到线程池? 并发的线程数量很多,并且每个线程都是执行一个时间很短的任务就结束了,这样频繁创建线程就会大大降低系统的效率,因为频繁创建线程和销毁线程需要时间. 因此 ...

  7. 基于webmagic的爬虫小应用--爬取知乎用户信息

    听到“爬虫”,是不是第一时间想到Python/php ? 多少想玩爬虫的Java学习者就因为语言不通而止步.Java是真的不能做爬虫吗? 当然不是. 只不过python的3行代码能解决的问题,而Jav ...

  8. M2事后分析汇报总结

    学霸网站项目Postmortem结果 M2之于M1的改进 文档和问答的整合 完成webservice 完成数据库触发器设计与完整性约束依赖(大规模) 优化学霸UI 资源的搜索 外部问题的搜索 文档的上 ...

  9. PHP高并发高负载系统架构

    PHP高并发高负载系统架构 1.为什么要进行高并发和高负载的研究 1.1.产品发展的需要 1.2.公司发展的需要 1.3.当前形式决定的 2.高并发和高负载的约束条件 2.1.硬件 2.2.部署 2. ...

  10. 03-Swift常量&变量

    什么是常量和变量 在Swift中规定:在定义一个标识符时必须明确说明该标识符是一个常量还是变量 使用let来定义常量,定义之后不可以修改 使用var来定义变量,定义之后可以修改 常量和变量的基本使用 ...