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

对于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. 1.7 使用电脑测试MC20的发送带中文的短信功能

    需要准备的硬件 MC20开发板 1个 https://item.taobao.com/item.htm?id=562661881042 GSM/GPRS天线 1根 https://item.taoba ...

  2. storage

    localStorage(本地存储),可以长期存储数据,没有时间限制,一天,一年,两年甚至更长,数据都可以使用. sessionStorage(会话存储),只有在浏览器被关闭之前使用,创建另一个页面时 ...

  3. (转)【腾讯 TMQ】 接口测试用例设计

    导语 这是我在其他的开源社区看到的一篇分享帖子.这篇文章的目的只是为大家提供一个思路,但是实现成本太高了,因为一个接口设计的接口测试用例很多,一般公司的接口数量几百到上千不等,每一个接口都设计这么多测 ...

  4. Objective-C系列总结之基础知识

    //第一个程序示例 #import <Foundation/Foundation.h> int main(int argc,const char * argv[]) { @autorele ...

  5. 建议10:numpy使用基础

    # -*- coding: utf-8 -*- import numpy as np #---------------------------------------- #-- 定义 ndarray ...

  6. bootstrap 模态框中弹出层 input不能获得焦点且不可编辑

    bootstrap 模态框中弹出层 input不能获得焦点且不可编辑 问题描述:bs框架支持一层model层的情况下,在模态框中弹出了自定义的弹出层.发现自定义弹出层的输入框不能获得焦点且不可编辑. ...

  7. jQuery之DOM操作大全

    jQuery属性操作 获取元素属性的语法:attr(name) 例子:$("#img1").attr("src"); 设置元素单个属性的语法:attr(key, ...

  8. Eclipse SVN插件设置

    项目开发中,开发人员用SVN来管理代码,在和服务器同步时,需要避免上传不必要的一些编译文件,如.class,.log,target等文件,这里需要设置同步选项. 打开Eclipse ---> W ...

  9. Introduction to vSphere Integrated Containers

    vSphere Integrated Containers enables IT teams to seamlessly run traditional workloads and container ...

  10. Eclipse4.2安装样式插件

    1.插件地址 http://eclipse-color-theme.github.com/update 点击Eclipse菜单 Help>>Install New Software... ...