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 ...
随机推荐
- Entity Framework技巧系列之一 - Tip 1 - 5
提示1. 在Entity Framework中怎样排序关系(Relationships) 问题: 在Entity Framework论坛中常会看到关于排序相关联项目的问题. 例如,想象你要查询客户,并 ...
- LeetCode OJ 110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- MVC4数据注解和验证
model中的验证注解特性: public class StuInfo { public int ID { get; set;} [Display(Name = "姓名")] // ...
- Linux下 Unison 实现文件双向同步
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://hx100.blog.51cto.com/44326/612301 一.Uniso ...
- 获取输入设备的vid和pid
一.获取/dev/input/event16设备的vid和pid testhid.c #include <linux/types.h> #include <linux/input.h ...
- centos7 python
yum -y install gcc cd /usr/local/src wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0a1 ...
- CodeForces 510B DFS水题
题目大意:在图中找到一个字符可以围成一个环(至少有环四个相同元素) 题目思路:对当前点进行搜索,如果发现可以达到某个已经被查找过的点,且当前点不是由这个点而来,则查找成功. #include<c ...
- centos6.5 安装git
1.安装编译git时需要的包 # yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel # yum ins ...
- php截取中文字符串,英文字符串,中英文字符串长度的方法
今天学习了php函数截取中文字符串,英文字符串,中英文字符串的函数使用方法.对中英文截取方法不理解,此处先做记录. PHP自带的函数如strlen().mb_strlen()都是通过计算字符串所占字节 ...
- 河南多校大一训练赛 E 开餐馆
题目链接:http://acm.hust.edu.cn/vjudge/contest/125004#problem/E 密码:acm Description 北大信息学院的同学小明毕业之后打算创业开餐 ...