A. Bits
来源:互联网 发布:淘宝上的avada主题 编辑:程序博客网 时间:2024/06/07 03:44
Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integerx.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and is maximum possible. If there are multiple such numbers find the smallest of them.
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers li, ri — the arguments for the corresponding query (0 ≤ li ≤ ri ≤ 1018).
For each query print the answer in a separate line.
31 22 41 10
137
The binary representations of numbers from 1 to 10 are listed below:
110 = 12
210 = 102
310 = 112
410 = 1002
510 = 1012
610 = 1102
710 = 1112
810 = 10002
910 = 10012
1010 = 10102
解题说明:此题只需要把数字转换为二进制,然后统计1的次数,最后找到一个区间内1最多的数。
#include<cstdio>#include <cstring>#include<cmath>#include<iostream>#include<algorithm>#include<vector>#include <map>using namespace std;int main() { int n; long long l,r; cin>>n; for(int i=0;i<n;i++) {cin>>l>>r;while((l|(l+1))<=r) {l|=l+1;}cout<<l<<endl;} return 0;}
- A. Bits
- codeforces 484a Bits
- CF 484A Bits
- codeforces 484 A-Bits
- CodeForces 484A Bits
- codeforces-484A Bits
- Codeforces 484A Bits
- codeforces 484A bits
- Codeforces-484A-Bits
- Rotate bits of a number
- A. Little Elephant and Bits
- A. Little Elephant and Bits
- Bits - CodeForces 484 A 水题
- codeforces 484A Bits 数论
- Codeforces 484A Bits(贪心)
- Codeforces 484A - Bits (贪心)
- Codeforces 484A. Bits 贪心
- Reverse bits of a given 32 bits unsigned integer
- Mathematica里面总有一些炫的特征
- Guice:轻量级IOC/DI 容器
- 在linux下用shell将tomcat做成服务
- 表的复制语句: select into 和 insert into select
- 我的Android使用openCV记录(1)
- A. Bits
- 1.7.什么是堆(heap)
- Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE]
- 工作反思总结
- Android系统启动流程
- iOS证书问题
- Linux Java 获取CPU使用率,内存使用率,磁盘IO,网络带宽使用率等等
- 将Bitmap中某个颜色替换成其他颜色
- Java 设计模式-原型模式