Claris and XOR(模拟)
Claris and XOR
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 332 Accepted Submission(s): 135
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.
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.
昨天的B题,我的理解力,我都惭愧了,自己写了好几个样例才完全搞懂。
从最高位到最低位贪心。

a 1 0 0 0 0 c 1 0 0 0 0 0
a 1 0 0 0 0 c 0 1 0 0 0 0
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
void solve(){
int t;
scanf("%d",&t);
while(t--){
ll a,b,c,d;
cin>>a>>b>>c>>d;
int x1,x2,y1,y2;
ll ans = ;
for(int i = ; i>=; i--){
x1 = (bool)(a&((ll)<<i));
x2 = (bool)(b&((ll)<<i));
y1 = (bool)(c&((ll)<<i));
y2 = (bool)(d&((ll)<<i));
if(x1 == x2&&y1 == y2){
if(x1 != y1){
ans += ((ll)<<i);
}
}
else if(x1 != x2&&y1 == y2){
ans += ((ll)<<i);
if(y1 == ){
b = ((ll)<<i) - ;
}
else{
a = ((ll)<<i);
}
}
else if(x1 == x2&&y1 != y2){
ans += ((ll)<<i);
if(x1 == ){
d = ((ll)<<i) - ;
}
else{
c = ((ll)<<i);
}
}
else if(x1 != x2&&y1 != y2){
ans += ((ll)<<(i+))-;
break;
}
}
cout<<ans<<endl;
}
}
int main()
{
solve();
return ;
}
卷珠帘
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
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 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. 然后有前 ...
- HDU 5683 zxa and xor 暴力模拟
zxa and xor 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5683 Description zxa had a great interes ...
- 清北学堂模拟赛d1t6 或和异或(xor)
题目描述 LYK最近在研究位运算,它研究的主要有两个:or和xor.(C语言中对于|和^) 为了更好的了解这两个运算符,LYK找来了一个2^n长度的数组.它第一次先对所有相邻两个数执行or操作,得到一 ...
- HDU 4825 Xor Sum(二进制的字典树,数组模拟)
题目 //居然可以用字典树...//用cin,cout等输入输出会超时 //这是从别处复制来的 #include<cstdio> #include<algorithm> #in ...
随机推荐
- hdu_5683_zxa and xor(非正解的暴力)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5683 题意: 问题描述 zxa最近对按位异或(exclusive disjunction)产生了极大的 ...
- PMBok项目管理
这就是项目管理的九大领域:整合管理.范围管理.时间管理.费用管理.质量管理.人力资源管理.沟通管理.风险管理.采购管理. 项目管理好像一头大象,将其大卸九块之后,要装进冰箱就容易多了. 看看书上是怎样 ...
- Inno Setup入门(十九)——Inno Setup类参考(5)
: Install Setup 2013-02-02 11:29 377人阅读 评论(0) 收藏 举报 单选按钮 单选按钮在安装中也很常见,例如同一个程序可以选择安装不同的性质的功能,例如选择32位或 ...
- c++判断一个字符串是否是数字
bool isNum(const string& str) { bool bRet = false; bool point = false; ) { return bRet; } ]) &am ...
- C++中的函数指针和函数对象总结
篇一.函数指针函数指针:是指向函数的指针变量,在C编译时,每一个函数都有一个入口地址,那么这个指向这个函数的函数指针便指向这个地址.函数指针的用途是很大的,主要有两个作用:用作调用函数和做函数的参数. ...
- Spring MVC中,事务是否可以加在Controller层
一般而言,事务都是加在Service层的,但是爱钻牛角尖的我时常想:事务加在Controller层可不可以.我一直试图证明事务不止可以加在Service层,还可以加在Controller层,但是没有找 ...
- Hibernate 系列教程17-查询缓存
在二级缓存配置成功的基础上进行查询缓存配置 Product public class Product { private Long id; private String name; Product.h ...
- Hibernate 系列教程14-继承-PerTable策略
Employee public class Employee { private Long id; private String name; HourlyEmployee public class H ...
- 使用Core Animation对象来实现动画
转载保留原文地址:http://blog.csdn.net/kqjob/article/details/10417461,转载的 在iOS中如果使用普通的动画则可以使用UIKit提供的动画方式来实现, ...
- [转]探究java IO之FileInputStream类
使用FileInputStream类创建的InputStream对象可以用于从文件读取内容.两个常用的构造函数如下所示: ? 1 2 FileInputStream(String filePath) ...