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#不显示在任务栏
在我用c#写一些小程序是总是希望,程序窗体不在任务栏上显示程序的窗体,c# Form提供了一个 属性值可以很好的解决这个问题 这个属性就是 ShowInTaskbar 在微软的官方声明格式为: pub ...
- Windows 2000 栈溢出 利用异常
当在一个函数(test)里面自定义了异常处理,如下: 那么在运行时,它会把自定义的异常处理函数MyExceptionhandler()的地址放入栈中(PUSH 004013CC) 然后把fs:[0]的 ...
- MacOS通过ssh连接基于Virtualbox的Ubuntu虚拟机
以前总是用Windows软件putty进行ssh连接,今天尝试使用macos. 实验环境:主机:macos 10.15.3 客户机:Ubuntu 18.04 默认情况下,Ubuntu没有安装SSH,需 ...
- UVA - 1645 Count (统计有根树)(dp)
题意:输入n(n <=1000),统计有多少个n结点的有根树,使得每个深度中所有结点的子结点数相同.输出数目除以109+7的余数. 分析: 1.dp[i],i个结点的有根树个数 2.假设n=7, ...
- POJ 1276:Cash Machine 多重背包
Cash Machine Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 30006 Accepted: 10811 De ...
- 十五、CI框架之自动加载数据库
一.在config的autoload.php文件中,如果写入以下代码,那么在控制器中无需再次加载数据库了,相当于全局自动加载数据库了 不忘初心,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码 ...
- 初识MyBatis-Generator
详细请见: http://www.mybatis.org/generator/quickstart.html 使用mybatis-generator-core-x.x.x.jar加上配置文件来生成 1 ...
- 干货 | 运维福音——Terraform自动化管理京东云
干货 | 运维福音--Terraform自动化管理京东云 原创: 张宏伟 京东云开发者社区 昨天 Terraform是一个高度可扩展的IT基础架构自动化编排工具,主张基础设施即代码,可通过代码集中管 ...
- HDU 3018 欧拉回路
HDU - 3018 Ant Country consist of N towns.There are M roads connecting the towns. Ant Tony,together ...
- Ka/ Ks|同义替换的三种路径|kaks_Calculator|
生命组学 研究old gene 和 young gene CAI选择信号:CGmutation信号 Neutrality plot:CG3与GC1.GC2的关系:平:mutation:正相关:sele ...