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 ...
随机推荐
- vzray服务端配置
打开securecrt登陆服务器 输入命令:bash <(curl -s -L https://git.io/vzray.sh)1 回车tcp 回车端口 回车默认 回车
- ACM-Fire Net
题目描述:Fire Net Suppose that we have a square city with straight streets. A map of a city is a squar ...
- 第一部分 JavaScript语言核心(四)
第九章 类和模块 P235 组合VS子类:组合优于继承 P236 类的层次结构和抽象类 第十章 正则达式的模式匹配 定义 JS中正则表达式用RegExp对象表示.直接量定义为包含在一堆斜杠(/)之间的 ...
- UVA - 12118 Inspector's Dilemma(检查员的难题)(欧拉回路)
题意:有一个n个点的无向完全图,找一条最短路(起点终点任意),使得该道路经过E条指定的边. 分析: 1.因为要使走过的路最短,所以每个指定的边最好只走一遍,所以是欧拉道路. 2.若当前连通的道路不是欧 ...
- 51nod 1022 石子归并 环形+四边形优化
1022 石子归并 V2 基准时间限制:1 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 收藏 关注 N堆石子摆成一个环.现要将石子有次序地合并成一堆.规定每次只能选相邻的2 ...
- SourceTree - 对Git的使用
SourceTree - 对Git的使用 一 .SourceTree简介 SourceTree 是 Windows 和Mac OS X 下免费的 Git 和 Hg 客户端,拥有可视化界面,容易上手操作 ...
- 201903-2 二十四点 Java
思路: 数据结构中,栈可以解决运算的问题.利用压栈和弹栈操作实现(这里用队列模拟).具体的: 遇到乘除号,弹出栈顶元素,将计算结果压入栈中.遇到加减号,将后面的数一起压入栈中. 注意: substri ...
- vector删除指定元素
#pragma once #include "stdafx.h" #include<windows.h> #include <vector> #includ ...
- 根据M3U8地址下载视频
下面展示的是通过M3U8地址,把这个地址转为一个视频文件:只是一个基本案例,当然,有些下载的M3U8文件里面格式是不一样的,还有的是加过密的,道理都是一个道理. import java.io.Buf ...
- salt如何查看文档帮助
1.查看普通模块和函数使用方法 salt 'minion' sys.doc module_name salt ‘minion' sys.doc module_name.function_name ...