给定两个整数:LR

∀ 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的更多相关文章

  1. 【BZOJ2337】[HNOI2011]XOR和路径 期望DP+高斯消元

    [BZOJ2337][HNOI2011]XOR和路径 Description 题解:异或的期望不好搞?我们考虑按位拆分一下. 我们设f[i]表示到达i后,还要走过的路径在当前位上的异或值得期望是多少( ...

  2. 【BZOJ2115】[Wc2011] Xor 高斯消元求线性基+DFS

    [BZOJ2115][Wc2011] Xor Description Input 第一行包含两个整数N和 M, 表示该无向图中点的数目与边的数目. 接下来M 行描述 M 条边,每行三个整数Si,Ti ...

  3. 【BZOJ4269】再见Xor 高斯消元

    [BZOJ4269]再见Xor Description 给定N个数,你可以在这些数中任意选一些数出来,每个数可以选任意多次,试求出你能选出的数的异或和的最大值和严格次大值. Input 第一行一个正整 ...

  4. 【bzoj4296】再见Xor

    4269: 再见Xor Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 176  Solved: 107[Submit][Status][Discuss ...

  5. 【bzoj2115】[Wc2011] Xor

    2115: [Wc2011] Xor Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 2512  Solved: 1049[Submit][Status ...

  6. 【Trie】The XOR Largest Pair

    [题目链接] https://loj.ac/problem/10050 [题意] 给出n个数,其中取出两个数来,让其异或值最大. [题解] 经典的01字典树问题. 首先需要把01字典树建出来. 然后对 ...

  7. 【BZOJ-4269】再见Xor 高斯消元 + 线性基

    4269: 再见Xor Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 131  Solved: 81[Submit][Status][Discuss] ...

  8. 【HackerRank】How Many Substrings?

    https://www.hackerrank.com/challenges/how-many-substrings/problem 题解 似乎是被毒瘤澜澜放弃做T3的一道题(因为ASDFZ有很多人做过 ...

  9. 【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 ...

随机推荐

  1. 使用Squid搭建HTTPS代理服务器

    由于经常去的一些国外网站如Google.Blogspot.Wordpress被"出现了技术问题",访问不了,于是我在自己的DigitalOcean云主机上搭建了一个 Squid代理 ...

  2. Mybatis+MSSql插入数据的同时并获取自增的ID

    在项目中遇到这样的情况,新增一个角色,这个角色有某些权限,这两个数据存在不同的表中,一个是sys_role,另外一个是sys_role_permission表,注意,现在的逻辑是这样的 1,在表sys ...

  3. VLC WebPlugin中文

    Documentation:WebPlugin 这篇文档讲述的是 VLC media player Web plugins 和怎样在网页使用它 Contents 1 介绍: 构建包含video的Web ...

  4. oracle中根据时间获取最新的一条数据

    order by kd.createtime 2.SELECT * FROM ( SELECT *,ROWNUM rn FROM t ORDER BY date_col DESC ) ,cg.bert ...

  5. 用Flex实现常见的几种布局

    用Flex实现常见的几种布局 1.水平,垂直居中. <style type="text/css"> .container{ display: flex; width: ...

  6. js intanceof 或 typeof

    typeof和instanceof的区别 typeof和instanceof都可以用来判断变量,它们的用法有很大区别: typeof会返回一个变量的基本类型,只有以下几种:number,boolean ...

  7. Yii GridView::widget

    GridView::widget文档 http://demos.krajee.com/grid GridView::widget([ 'dataProvider' => $dataProvide ...

  8. Laragon集成开发环境+配置Xdebug+postman运行Xdebug

    [ Laravel 5.5 文档 ] 快速入门 —— 使用 Laragon 在 Windows 中搭建 Laravel 开发环境:http://laravelacademy.org/post/7754 ...

  9. NodeJS版本EasyDarwin开源流媒体服务器开发心得

    title: Node版本EasyDarwin开发心得 date: 2018-03-27 22:46:15 tags: 年后着手Node版本EasyDarwin的开发工作,截止到今天2018年03月2 ...

  10. A Universally Unique IDentifier (UUID) URN Namespace

    w Network Working Group P. Leach Request for Comments: 4122 Microsoft Category: Standards Track M. M ...