【HackerRank】Maximizing XOR
2024-09-06 09:53:38
给定两个整数: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); }
}
最新文章
- GamePinTu
- [Linux] - CentOS中文乱码解决办法
- SQL Server Code tips (持续更新)
- ffmpeg常用命令
- C++pair类型
- Scrum会议2(Beta版本)
- 图解SSL/TLS协议
- 在Linux上安装JDK7
- MFC应用程序的开发流程
- pair work-Elevator Schedule
- Permutations,Permutations II,Combinations
- MFC网页访问的实现示例
- PAT (Advanced Level) 1113. Integer Set Partition (25)
- md编辑器测试
- 【SSH系列】深入浅出SpringMvc+入门Demo
- vue axios 封装(二)
- Android组件化demo实现以及遇坑分享
- P2331 [SCOI2005]最大子矩阵 (动规:分类讨论状态)
- js函数定义和调用
- Delphi获取公网IP地址函数
热门文章
- UVA1658 Admiral 拆点法解决结点容量(路径不能有公共点,容量为1的时候) 最小费用最大流
- atom安装插件
- Java进阶02 异常处理(转载)
- Eclipse 任务管理
- SQL Server 阻止了对组件“Ad Hoc Distributed Queries”的 STATEMENT“OpenRowset/OpenDatasource”的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用 sp_configure 启用“Ad Hoc Distributed Queries”。有关启用“Ad Hoc Distributed Queries”
- 不通过AppStore,在iOS设备上直接安装应用程序的原理
- IIPP迷你项目(三)“Stopwatch: The Game”
- EasyNVR现场部署搭配EasyNVS云端集中控制应用于幼儿园直播场景的最佳方案!
- HUST 1354 - Rubiks (DP)
- virsh命令行管理工具