【HackerRank】Maximizing XOR
给定两个整数:L 和 R
∀ L ≤ A ≤ B ≤ R, 找出 A xor B 的最大值。
输入格式
第一行包含 L 第一行包含 R
数据范围
1 ≤ L ≤ R ≤ 103
输出格式
输出最大的异或和
题解:
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*; public class Solution {
/*
* Complete the function below.
*/ static int maxXor(int l, int r) {
int maxx = 0;
for(int i = l;i <= r;i++){
for(int j = l;j <= r;j++){
if(i != j)
maxx = Math.max(maxx,i^j);
}
}
return maxx; } public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int res;
int _l;
_l = Integer.parseInt(in.nextLine()); int _r;
_r = Integer.parseInt(in.nextLine()); res = maxXor(_l, _r);
System.out.println(res); }
}
【HackerRank】Maximizing XOR的更多相关文章
- 【BZOJ2337】[HNOI2011]XOR和路径 期望DP+高斯消元
[BZOJ2337][HNOI2011]XOR和路径 Description 题解:异或的期望不好搞?我们考虑按位拆分一下. 我们设f[i]表示到达i后,还要走过的路径在当前位上的异或值得期望是多少( ...
- 【BZOJ2115】[Wc2011] Xor 高斯消元求线性基+DFS
[BZOJ2115][Wc2011] Xor Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ...
- 【BZOJ4269】再见Xor 高斯消元
[BZOJ4269]再见Xor Description 给定N个数,你可以在这些数中任意选一些数出来,每个数可以选任意多次,试求出你能选出的数的异或和的最大值和严格次大值. Input 第一行一个正整 ...
- 【bzoj4296】再见Xor
4269: 再见Xor Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 176 Solved: 107[Submit][Status][Discuss ...
- 【bzoj2115】[Wc2011] Xor
2115: [Wc2011] Xor Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 2512 Solved: 1049[Submit][Status ...
- 【Trie】The XOR Largest Pair
[题目链接] https://loj.ac/problem/10050 [题意] 给出n个数,其中取出两个数来,让其异或值最大. [题解] 经典的01字典树问题. 首先需要把01字典树建出来. 然后对 ...
- 【BZOJ-4269】再见Xor 高斯消元 + 线性基
4269: 再见Xor Time Limit: 10 Sec Memory Limit: 512 MBSubmit: 131 Solved: 81[Submit][Status][Discuss] ...
- 【HackerRank】How Many Substrings?
https://www.hackerrank.com/challenges/how-many-substrings/problem 题解 似乎是被毒瘤澜澜放弃做T3的一道题(因为ASDFZ有很多人做过 ...
- 【HackerRank】Lonely Integer
There are N integers in an array A. All but one integer occur in pairs. Your task is to find out the ...
随机推荐
- hdu1695 GCD2 容斥原理 求x属于[1,b]与y属于[1,d],gcd(x,y)=k的对数。(5,7)与(7,5)看作同一对。
GCD Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Sub ...
- dp解Codeforces Round #260 (Div. 2)C. Boredom
#include<iostream> #include<map> #include<string> #include<cstring> #include ...
- Oracle基础学习登陆SQLPLUS(一)
SQLPLUS是ORACLE公司开发的非常简洁的管理工具,SQLPLUS是最好的,最核心的ORACLE管理工具.SQLPLUS简洁而高效,舍弃浮华,反璞归真.使用sqlplus,进入sqlplus并进 ...
- Android中*_handle_t/ANativeWindowBuffer/ANativeWindow/GraphicBuffer/Surface的关系
在阅读SurfaceFlinger HardwareComposer以及gralloc相关代码的过程中,我们经常会遇到native_handle private_handle_t ANativeWin ...
- jQuery 尺寸 方法
jQuery 提供多个处理尺寸的重要方法: width() height() innerWidth() innerHeight() outerWidth() outerHeight()
- IntelliJ IDEA使用手册
开发工具现在转到IDEA了,看到关于该工具很好的入门文档,于是记录一下: IntelliJ IDEA 使用教程
- 【BZOJ1731】[Usaco2005 dec]Layout 排队布局 差分约束
[BZOJ1731][Usaco2005 dec]Layout 排队布局 Description Like everyone else, cows like to stand close to the ...
- oracle clob字段去除html标签
通过正则表达式的方式去除html标签 select regexp_replace(content,'</?[^>]*>|nbsp;|&','') content from T ...
- 【Windows下DLL查找顺序 】
一.写作初衷 在Windows下单个DLL可能存在多个不同的版本,若不特别指定DLL的绝对路径或使用其他手段指定,在应用程序加载DLL时可能会查找到错误的版本,进而引出各种莫名其妙的问题.本文主要考虑 ...
- php自定义函数: 时间转换成智能形式
function time_trans($paratime,$suffix=false){ $now_time = time(); $dur = $now_time - $paratime; $suf ...