可得应当优先寻找最大的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的更多相关文章

  1. HDU3047 Zjnu Stadium 【带权并查集】

    HDU3047 Zjnu Stadium Problem Description In 12th Zhejiang College Students Games 2007, there was a n ...

  2. bzoj 1699: [Usaco2007 Jan]Balanced Lineup排队 分块

    1699: [Usaco2007 Jan]Balanced Lineup排队 Time Limit: 5 Sec  Memory Limit: 64 MB Description 每天,农夫 John ...

  3. [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 ...

  4. [LeetCode] Reverse Bits 翻转位

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  5. 【leetcode】Number of 1 Bits

    题目描述: Write a function that takes an unsigned integer and returns the number of '1' bits it has (als ...

  6. Leetcode-190 Reverse Bits

    #190. Reverse Bits Reverse bits of a given 32 bits unsigned integer. For example, given input 432615 ...

  7. CodeForces 485C Bits[贪心 二进制]

    C. Bits time limit per test1 second memory limit per test256 megabytes inputstandard input outputsta ...

  8. uva12545 Bits Equalizer

    uva12545 Bits Equalizer You are given two non-empty strings S and T of equal lengths. S contains the ...

  9. LeetCode Counting Bits

    原题链接在这里:https://leetcode.com/problems/counting-bits/ 题目: Given a non negative integer number num. Fo ...

随机推荐

  1. Elasticsearch 删除文档

    章节 Elasticsearch 基本概念 Elasticsearch 安装 Elasticsearch 使用集群 Elasticsearch 健康检查 Elasticsearch 列出索引 Elas ...

  2. POJ 3096:Surprising Strings

    Surprising Strings Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6258   Accepted: 407 ...

  3. js连续的日期判断,判断相差几天

    var startTime=Date.parse(new Date('2020-02-28')); var endTime=Date.parse(new Date('2020-02-29')); $. ...

  4. nginx报错

    1. nginx报错 nginx: [error] invalid PID number "" in "/usr/local/nginx/logs/nginx.pid&q ...

  5. jquery判断当前浏览器是否是IE

    if (window.ActiveXObject || "ActiveXObject" in window){ layer.msg("This page does not ...

  6. 吴裕雄--天生自然JAVA SPRING框架开发学习笔记:Spring JDK动态代理

    JDK 动态代理是通过 JDK 中的 java.lang.reflect.Proxy 类实现的.下面通过具体的案例演示 JDK 动态代理的使用. 1. 创建项目 在 MyEclipse 中创建一个名称 ...

  7. quartz详解4:quartz线程管理

    http://blog.itpub.NET/11627468/viewspace-1766967/ quartz启动后有多个线程同时在跑.启动时会启动主线程.集群线程.检漏线程.工作线程.主线程负责查 ...

  8. 统计Shell脚本执行时间

    统计Shell脚本执行时间,帮助分析改进脚本执行 用 date 相减 #!/bin/bash startTime=`date +%Y%m%d-%H:%M:%S` startTime_s=`date + ...

  9. 【转】centos7轻松搭建文件服务器

    1.安装apache服务器 yum install httpd 2:启动httpd服务 service httpd start 3:查看httpd服务器的版本 4:修改访问端口和文件路径,以防端口冲突 ...

  10. VUE.js入门学习(2)-基础精讲

    1.VUE 实例 - 一个项目是有很多的vue实例拼装的.每一个组建就是vue的实例. var vm = new Vue() 2.VUE 实例生命周期钩子 生命周期函数:VUE实例在某一个时间点会自动 ...