hdu 5661 Claris and XOR
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
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.
1 2 3 4
5 7 13 15
11
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的更多相关文章
- HDU 5661 Claris and XOR 贪心
题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5661 bc(中文):http://bestcoder.hdu.edu.cn/contests ...
- BC之Claris and XOR
http://acm.hdu.edu.cn/showproblem.php?pid=5661 Claris and XOR Time Limit: 2000/1000 MS (Java/Others) ...
- Claris and XOR(模拟)
Claris and XOR Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)To ...
- Claris and XOR
Problem Description Claris loves bitwise operations very much, especially XOR, because it has many b ...
- HDU5661 Claris and XOR
我们求二进制是怎么求的呢:先看看二进制的每一位代表多大:.......32 16 8 4 2 1 假如n=10, ..... 32>n ,不要. 16>n,不要. 8<=n,要,然后 ...
- HDU 5683 zxa and xor 暴力模拟
zxa and xor 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5683 Description zxa had a great interes ...
- 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 ...
- hdu 5269 ZYB loves Xor I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission( ...
- bestcoder r44 p3 hdu 5270 ZYB loves Xor II
这是昨晚队友跟我说的题,不知道当时是什么玄幻的事件发生了,,我看成了两两相乘的XOR 纠结了好长时间间 不知道该怎么办 今天早上看了下这道题,发现是两两相加的XOR 然后就想了想昨晚的思路 发现可做 ...
随机推荐
- 游戏中的人工智能——初探AI
一.游戏中的人工智能 让游戏具有挑战性: 让游戏好玩的关键因素是为之找到合适的难度等级: 人工智能在游戏中的作用是通过提供富有挑战性的竞争对象来让游戏更好玩,而在游戏中行动逼真的非玩家角色(NPC), ...
- BestCoder Round #90 //div all 大混战 一题滚粗 阶梯博弈,树状数组,高斯消元
BestCoder Round #90 本次至少暴露出三个知识点爆炸.... A. zz题 按题意copy Init函数 然后统计就ok B. 博弈 题 不懂 推了半天的SG..... 结果这 ...
- 小记:Bmob云端代码测试APNS推送功能 #代码片段
function onRequest(request, response, modules) { var push = modules.oPush; push.send({ "data&qu ...
- TCP的拥塞控制
1.引言 计算机网络中的带宽.交换结点中的缓存和处理机等,都是网络的资源.在某段时间,若对网络中某一资源的需求超过了该资源所能提供的可用部分,网络的性能就会变坏.这种情况就叫做拥塞. 拥塞控制就是防止 ...
- python学习笔记-多进程
multiprocessing from multiprocessing import Process import time def f(name): time.sleep(2) print('he ...
- KinectV1+Ubuntu 14.04安装教程
前言 个人理解错误的地方还请不吝赐教,转载请标明出处,内容如有改动更新,请看原博:http://www.cnblogs.com/hitcm/ 如有任何问题,feel free to ...
- spring mvc(1):基础入门
依赖 pom.xml ( maven ) <properties> <spring.version>3.0.5.RELEASE</spring.version> ...
- 无法删除服务器 'old_server_name',因为该服务器用作复制过程中的发布服务器。 (Microsoft SQL Server,错误: 20582)
无法删除服务器 'old_server_name',因为该服务器用作复制过程中的发布服务器. (Microsoft SQL Server,错误: 20582) 2013-01-05 15:02 478 ...
- android sdk镜像站点
http://android-mirror.bugly.qq.com:8080/include/usage.html Windows A. 打开Android SDK Manager B. 设置代理 ...
- 一些webGL的资源
作为一个新手,把资源写在这里. 一个简介: http://www.html5china.com/HTML5features/WebGL/20111129_2985.html 类似NEHE OPENGL ...