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 ...
随机推荐
- 干货分享|留学Essay怎么写?
留学生活其实就是分割成一个个deadline,留学就是赶完一个又一个deadline.朋友同学的革命情感源自赶一个个deadline时候的不离不弃,相知相守,无数个夜里大家群里打卡,你今天Essay写 ...
- linux系统pid的最大值研究
内核源码探查 通过对linux内核源码的追踪,可以看到对pid最大值的限定最终集中到include/linux/threads.h文件中的PID_MAX_DEFAULT上了,代码如下: /* * Th ...
- 大二暑假第四周总结--开始学习Hadoop基础(三)
简单学习云数据库系统架构(以UMP系统为例) 一.UMP系统概述 低成本和高性能的MySQL云数据库方案 二.UMP系统架构 架构设计遵循以下原则: 保持单一的系统对外入口,并且为系统内部维护单一的资 ...
- vue组件化应用构建
组件系统是 Vue 的另一个重要概念,因为它是一种抽象,允许我们使用小型.独立和通常可复用的组件构建大型应用.仔细想想,几乎任意类型的应用界面都可以抽象为一个组件树: 在 Vue 里,一个组件本质上是 ...
- 18 12 25 css 基本语法以及页面使用
css的定义方法是: 选择器 { 属性:值; 属性:值; 属性:值;} 选择器是将样式和页面元素关联起来的名称,属性是希望设置的样式属性每个属性有一个或多个值 css页面引入方法: 1.外联式:通过l ...
- PyGame快速入门
pygame 快速入门 目标 项目准备 使用 pygame 创建图形窗口 理解 图像 并实现图像绘制 理解 游戏循环 和 游戏时钟 理解 精灵 和 精灵组 项目准备 新建 飞机大战 项目 新建一个 h ...
- LeetCode 687. Longest Univalue Path 最长同值路径 (C++/Java)
题目: Given a binary tree, find the length of the longest path where each node in the path has the sam ...
- ZOJ- 2562 反素数使用
借用了下东北师大ACM的反素数模版. 本来我是在刷线段树的,有一题碰到了反素数,所以学了一下..有反素数的存在,使得一个x ,使得x的约数个数,在1 到 x的所有数里面,是最大的. 这里面还涉及安叔那 ...
- 解决XML警告"No grammar constraints (DTD or XML Schema) referenced in the document"
解决办法: 顶部有这两行信息即可解决警告: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ...
- postman问题
问题1:postman请求出现 'SSL certificate verification' ,实际为https的问题 解决: 1)关闭fiddler 2)或在File > Settings & ...