这道题直接去构造答案即可。

对于l的二进制表示,从右到左一位一位的使其变为1,当不能再变了(再变l就大于r了)时,答案就是l。

这种方法既可以保证答案大于等于l且小于等于r,也可以保证二进制表示时的1最多。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<stack>
#include<queue>
#include<cctype>
#include<sstream>
using namespace std;
#define pii pair<int,int>
#define LL long long int
const int eps=1e-;
const int INF=;
const int maxn=+;
int n;
LL l,r,p; int main()
{
//freopen("in9.txt","r",stdin);
//freopen("out.txt","w",stdout);
scanf("%d",&n);
while(n--)
{
scanf("%I64d%I64d",&l,&r);
p=;
while()
{
if((l|p)>r)
{
printf("%I64d\n",l);
break;
}
else
{
l|=p;
p*=;
}
}
}
//fclose(stdin);
//fclose(stdout);
return ;
}

Codeforces Round #276 (Div. 2)C. Bits(构造法)的更多相关文章

  1. Codeforces Round #276 (Div. 1) A. Bits 二进制 贪心

    A. Bits Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/problem/A Des ...

  2. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits

    http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...

  3. Codeforces Round #276 (Div. 1) A. Bits 贪心

    A. Bits   Let's denote as  the number of bits set ('1' bits) in the binary representation of the non ...

  4. C. Bits (Codeforces Round #276 (Div. 2) )

    题目大意:给你两个数l,r(l<r),求一个数是大于等于l且小于等于r的数中二进制数的1的个数最多,如果1的个数相同则取最小的那个(翻译渣,请见谅!) 思路:把左区间L化为二进制,再把左区间的二 ...

  5. codeforces 484a//Bits// Codeforces Round #276(Div. 1)

    题意:给出区间[ll,rr],求中间一个数二进制表示时一的个数最多. 写出ll和rr的二进制,设出现第一个不同的位置为pos(从高位到低位),找的数为x,那么为了使x在[ll,rr]内,前pos-1个 ...

  6. Codeforces Round #339 (Div. 1) C. Necklace 构造题

    C. Necklace 题目连接: http://www.codeforces.com/contest/613/problem/C Description Ivan wants to make a n ...

  7. Codeforces Round #181 (Div. 2) A. Array 构造

    A. Array 题目连接: http://www.codeforces.com/contest/300/problem/A Description Vitaly has an array of n ...

  8. Codeforces Round #306 (Div. 2) ABCDE(构造)

    A. Two Substrings 题意:给一个字符串,求是否含有不重叠的子串"AB"和"BA",长度1e5. 题解:看起来很简单,但是一直错,各种考虑不周全, ...

  9. Codeforces Round #276 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...

随机推荐

  1. virt-viewer的简单使用

    virt-viewer 简介:  virt-viewer是一个用于显示虚拟机的图形控制台的最小工具. 控制台使用VNC或SPICE访问协议. 可以基于其名称,ID或UUID来引用guest虚拟机.如果 ...

  2. python glob

    http://python.jobbole.com/81552/ glob模块是最简单的模块之一,内容非常少.用它可以查找符合特定规则的文件路径名.跟使用windows下的文件搜索差不多.查找文件只用 ...

  3. VC6.0中添加库文件和头文件

    附加头文件包含 VC6.0中: VC6.0默认include包含路径:Tools>Options>Directories>Include files. 对于特定项目的头文件包含,在“ ...

  4. vscode常用快捷键及常用设置

    快捷键 ctrl+b 切换侧边栏 ctrl+\ 拆分编辑器 ctrl+鼠标滚轮 缩放编辑器的字体 alt+shift+f 整理代码格式 alt+z 切换自动换行 ctrl+· 打开终端调试 ctrl+ ...

  5. 【HackerRank】Encryption

    One classic method for composing secret messages is called a square code.  The spaces are removed fr ...

  6. Java Collection API

    在 Java2中,有一套设计优良的接口和类组成了Java集合框架Collection,使程序员操作成批的数据或对象元素极为方便.这些接口和类有很多对抽象数据类型操作的API,而这是我们常用的且在数据结 ...

  7. JSP DAO(Model)

    示例代码: 1. Users类 package com.po; public class Users { private String username; private String passwor ...

  8. Go tail库

    HP团队出的tail库,常用于日志收集 示例代码: package main import ( "github.com/hpcloud/tail" "fmt" ...

  9. TypeScript手册1 - 基本类型和接口

    基本类型 像基本的JavaScript一样,TypeScript支持numbers, strings, structures, boolean等基本类型,而扩展的enum等类型,为编程提供了更多帮助. ...

  10. Kafaka高可用集群环境搭建

    zk集群环境搭建:https://www.cnblogs.com/toov5/p/9897868.html 三台主机每台的Java版本1.8 下面kafka集群的搭建:  3台虚拟机均进行以下操作:  ...