ZJNU 1699 - Bits
可得应当优先寻找最大的2^n-1这个数
如果l的位数不等于r的位数,那么这个数 2^n-1 就是最优解(每一位全为1)
如果l和r的位数相同,先看r是否符合 2^n-1,符合直接返回,不符合的话拆除最高位继续寻找
例如 l=10 r=14
即1010~1110 B
l和r位数相同且r不全为1
则可以拆除最高位1后
寻找10~110B中位数最大的最小数
位数不同,直接找到11B返回
则最终答案为1000B+11B=8+3=11
#include<stdio.h>
typedef long long ll;
ll fd(ll a,ll b)
{
ll i;
for(i=;i<=b+;i*=);
i/=;//找出小于等于i的最大的2的幂次
if(a<i)
return i-;
else
return fd(a-i,b-i)+i;//拆出最高位的1,然后寻找其余低位上的最大符合题意的值
}
int main(){
int T,t;
ll a,b;
scanf("%d",&T);
for(t=;t<T;t++)
{
scanf("%lld%lld",&a,&b);
printf("%lld\n",fd(a,b));
} return ;
}
ZJNU 1699 - Bits的更多相关文章
- HDU3047 Zjnu Stadium 【带权并查集】
HDU3047 Zjnu Stadium Problem Description In 12th Zhejiang College Students Games 2007, there was a n ...
- bzoj 1699: [Usaco2007 Jan]Balanced Lineup排队 分块
1699: [Usaco2007 Jan]Balanced Lineup排队 Time Limit: 5 Sec Memory Limit: 64 MB Description 每天,农夫 John ...
- [LeetCode] Number of 1 Bits 位1的个数
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...
- [LeetCode] Reverse Bits 翻转位
Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...
- 【leetcode】Number of 1 Bits
题目描述: Write a function that takes an unsigned integer and returns the number of '1' bits it has (als ...
- Leetcode-190 Reverse Bits
#190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432615 ...
- CodeForces 485C Bits[贪心 二进制]
C. Bits time limit per test1 second memory limit per test256 megabytes inputstandard input outputsta ...
- uva12545 Bits Equalizer
uva12545 Bits Equalizer You are given two non-empty strings S and T of equal lengths. S contains the ...
- LeetCode Counting Bits
原题链接在这里:https://leetcode.com/problems/counting-bits/ 题目: Given a non negative integer number num. Fo ...
随机推荐
- C# Process类详解
C# Process类详解 Process[] processes = Process.GetProcessesByName(current.ProcessName); 根据进程名字找到所有进程,返回 ...
- AD在更新PCB的时候,每次封装都会改变位置?
转载:https://blog.csdn.net/abc87891842/article/details/52538660 3.如果是很多元件的ID不一致, 手动修改太麻烦了, 可以使用AD的 &qu ...
- CF 767#
A题的话,用一个priority_queue维护一下,直到最大的符合要求才出来,,(一开始记错了,,2333写成了小根堆...) #include<bits/stdc++.h> #defi ...
- <老古董>1962年的线性支持向量机解法
我们说“训练”支持向量机模型,其实就是确定"最大间隔超平面". 用数学语言来说就是确定一个最优的W.好比训练一个逻辑回归模型的目的是确定最优的W和b. 输入 X,为一个n维向量 输 ...
- HDU 1226 超级密码(BFS) (还需研究)
Time Limit:10000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Desc ...
- 【数据结构】C++语言环形队列的实现
队列--先进先出 队列的一个缺点--出队后的内存空间浪费了,不能二次利用 环形队列--解决以上缺点的队列,用过的内存空间可以重复利用 github: https://github.com/HITFis ...
- Python基本数据类型之字符串
Python转义字符 在需要在字符中使用特殊字符时,python用反斜杠(\)转义字符.如下表: 转义字符 描述 \(在行尾时) 续行符 \\ 反斜杠符号 \' 单引号 \" 双引号 \a ...
- 理解Production- Ready特性
1.外部配置(externalized configuration) 1).基于环境变量的配置 2).基于YAML的配置 3).默认配置值 2.健康检查(health checks) 1).它是否有一 ...
- mybatis+maven+父子多模块进行crud以及动态条件查询
使用IDEA创建maven项目,File→New→Project→maven→Next→填写GroupId(例:com.zyl)和ArtifactId(mybatis-demo-parent)→Nex ...
- POJ 1844:Sum ”滚动“数组
Sum Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 10494 Accepted: 6895 Description ...