【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 ...
随机推荐
- LeetCode560. Subarray Sum Equals K
Description Given an array of integers and an integer k, you need to find the total number of contin ...
- 2017 Wuhan University Programming Contest (Online Round) B Color 树形dp求染色方法数
/** 题目:Color 链接:https://oj.ejq.me/problem/23 题意:给定一颗树,将树上的点最多染成m种颜色,有些节点不可以染成某些颜色.相邻节点颜色不同.求染色方法数. 思 ...
- datagrid返回记录为0时显示“没有记录”
datagrid返回记录为0时显示“没有记录”,此问题的 <script>var myview = $.extend({},$.fn.datagrid.defaults.view,{ on ...
- 如需在 HTML 页面中插入 JavaScript,请使用 <script> 标签。
如需在 HTML 页面中插入 JavaScript,请使用 <script> 标签. <script> 和 </script> 会告诉 JavaScript 在何处 ...
- Codeforces 455A Boredom 取数字的dp
题目链接:点击打开链接 给定一个n长的序列 删除x这个数就能获得x * x的个数 的分数,然后x+1和x-1这2个数会消失.即无法获得这2个数的分数 问最高得分. 先统计每一个数出现的次数.然后dp一 ...
- [Unity基础]移动平台下的文件读写
From:http://blog.csdn.net/lyh916/article/details/52161633 参考链接: http://www.cnblogs.com/murongxiaopif ...
- java微信开发API解析(四)-自己定义菜单以及个性化菜单实现
全局说明 * 具体说明请參考前两篇文章. 本文说明 *本文分为五部分: * 工具类AccessTokenUtils的封装 * 自己定义菜单和个性化菜单文档的阅读解析 * 菜单JSON的分析以及构建相应 ...
- POJ 2479 Maximum sum(双向DP)
Maximum sum Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 36100 Accepted: 11213 Des ...
- SQL Server 还原错误“restore database正在异常终止 错误 3154”
今天在还原数据库时,先建立相同名字的数据库,然后在该数据库上右键还原数据库.遇到了这样的一个错误: “备份集中的数据库备份与现有的 'RM_DB' 数据库不同. RESTORE DATABASE 正在 ...
- hoj 2739 中国邮局问题
/*若原图的基图不连通, 或者存在某个点的入度或出度为 0 则无解. 统计所有点的入度出度之差 Di, 对于 Di > 0 的点, 加边(s, i, Di, 0); 对于 Di < 0 的 ...