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 然后就想了想昨晚的思路 发现可做 ...
随机推荐
- [整理]一个有关Latch(锁存器)的有趣问题
起源 今天诳论坛,突然发现了一个有关latch的问题,由于对D Flip-Flop和Latch还有些疑问,就点击了进去,一看果然有些意思,也挺有学习意义的,于是本文就诞生了.喊出口号~Just not ...
- js面向对象编程:if中可以使用那些作为判断条件呢?
作者来源http://www.2cto.com/kf/201407/314978.html搬运 在所有编程语言中if是最长用的判断之一,但在js中到底哪些东西可以在if中式作为判断表达式呢? 例如如何 ...
- linux下添加链接与删除链接(ln命令的用法)
添加链接使用ln命令用法:#ln --help用法:ln [选项]... 目标 [链接名]或:ln [选项]... 目标... 目录或:ln [选项]... --target-directory=目录 ...
- C#实现简单的委托异步调用
delegate void textAsy(); static void Main(string[] args) { textAsy t = texts; AsyncCallback callBack ...
- jqueryValidation使用
jq form表单前端校验可以使用jq插件jquery-validation.js.具体的使用方法: 1.引入文件: <link rel="stylesheet" href= ...
- Http协议与TCP协议简单理解(转)
在C#编写代码,很多时候会遇到Http协议或者TCP协议,这里做一个简单的理解.TCP协议对应于传输层,而HTTP协议对应于应用层,从本质上来说,二者没有可比性.Http协议是建立在TCP协议基础之上 ...
- 浅谈SDN和NFV之间的关系
一个行业固定设备的折旧周期很长,任何变革的发生都绝非易事,但是网络却一次性面临两项革新--软件定义网络(SDN)和网络功能虚拟化(NFV),在变革网络的过程中,二者若想取得成功可能会依赖彼此的技术,或 ...
- vs
https://www.visualstudio.com/downloads/download-visual-studio-vs
- vs2015 无法启动IIS Express Web服务器
今天在VS2015上装了 之后无法启动IIS Express Web服务器. 然后我去查看了windows日志发现vs创建的虚拟目录不见了(至于是不是以上原因导致的没去查明) 然后在vs2015中点击 ...
- 关于maven中央仓库jar包不存在问题
最近接手一个maven项目,引入依赖的时候报了一个 Missing artifact com.oracle:ojdbc6:jar:12.1.0.1 pom.xml 的错误,网上一查,原来是Oracle ...