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 ... 
随机推荐
- NumPy 数组迭代
			章节 Numpy 介绍 Numpy 安装 NumPy ndarray NumPy 数据类型 NumPy 数组创建 NumPy 基于已有数据创建数组 NumPy 基于数值区间创建数组 NumPy 数组切 ... 
- docker安装出现"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"
			今天按照这个教程使用WSL安装docker时遇到了个问题: 使用命令:$ docker search mysql 出现:Cannot connect to the Docker daemon at u ... 
- bat 卸载程序的脚本
			@echo off :: BatchGotAdmin :------------------------------------- REM --> Check for permissions & ... 
- Neo4j--UNIQUE约束
			UNIQUE简介 和关系型数据库一样,对数据进行约束作用. 比如在某个属性上不能插入重复的节点. 比如属性的完整性约束. 创建UNIQUE约束 创建UNIQUE语法 CREATE CONSTRAINT ... 
- mongodb replication set 主从切换
			今天被问到mongodb副本集主从切换的问题,然后发现没有相关命令的中文文档,这里翻译记录一下 rs.stepDown() rs.stepDown(stepDownSecs, secondaryCat ... 
- AD在更新PCB的时候,每次封装都会改变位置?
			转载:https://blog.csdn.net/abc87891842/article/details/52538660 3.如果是很多元件的ID不一致, 手动修改太麻烦了, 可以使用AD的 &qu ... 
- 使用IDEA打对应结构的Jar包
			发布环境的内容和自己项目默认打包的样式不一样,就需要自定义打印jar包内容. 1.打开右上角项目结构 2.进行图片相关设置 3.直接进行打包,包会出现在class文件里面.解压软件解压开就是自己想要的 ... 
- 2018出炉50道iOS面试题
			基础: 1.如何令自己所写的对象具有拷贝功能? 若想令自己所写的对象具有拷贝功能,则需实现 NSCopying 协议.如果自定义的对象分为可变版本与不可变版本,那么就要同时实现 NSCopying与 ... 
- tableau-参数
			tableau参数可用在计算字段.筛选器和参考线中替换常量值得动态值. 三种方式:1.在计算字段中使用筛选器 案例动态替换计算字段中设定的目标值. 创建参数 以参数值创建计算字段 2.筛选器中使用参数 ... 
- mysql 时区问题导致的时间相差14小时
			1.mysql 字段名称 类型 begin_time TIME begin_time=08:18:39 2.java数据库连接串 jdbc:mysql://x.x.x.x:3306/y?useUnic ... 
