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

思路:把左区间L化为二进制,再把左区间的二进制的从最小位开始,每位变为1,因为这是在当前1的个数中最小的且大于L的。条件是小于等于右区间R。

代码:

 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stdio.h>
#include <cstring>
#include<algorithm>
using namespace std;
__int64 bits[];
int main()
{
int t;
__int64 l,r;
scanf("%d",&t);
while(t--)
{
__int64 ans;
memset(bits,,sizeof(bits));
scanf("%I64d%I64d",&l,&r);
ans=l;
int i=;
while(l>)
{
bits[i++]=(l%);
l=l/;
}
int len=i;
for(i=;; i++)
{
bits[i]=;
__int64 temp=;
for(int j=; j<max(len,i+); j++)
{
temp+=(bits[j]<<j);
}
if(temp<=r)
ans=temp;
else
break;
}
printf("%I64d\n",ans);
}
return ;
}

一开始把bits数组定义为int了运行错误,好像是temp+=(bits[j]<<j)这一步位运算爆int 了orz~~

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

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

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

  2. 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 ...

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

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

  4. 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 ...

  5. Codeforces Round #276 (Div. 2)C. Bits(构造法)

    这道题直接去构造答案即可. 对于l的二进制表示,从右到左一位一位的使其变为1,当不能再变了(再变l就大于r了)时,答案就是l. 这种方法既可以保证答案大于等于l且小于等于r,也可以保证二进制表示时的1 ...

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

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

  7. Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)

    链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...

  8. Codeforces Round #276 (Div. 1) E. Sign on Fence 二分+主席树

    E. Sign on Fence   Bizon the Champion has recently finished painting his wood fence. The fence consi ...

  9. Codeforces Round #276 (Div. 2)

    A. Factory 题意:给出a,m,第一天的总量为a,需要生产为a%m,第二天的总量为a+a%m,需要生产(a+a%m)%m 计算到哪一天a%m==0为止 自己做的时候,把i开到1000来循环就过 ...

随机推荐

  1. pthread_detach(pthread_self())

    pthread_detach(pthread_self()) 将状态改为unjoinable状态,确保资源的释放.其实简单的说就是在线程函数头加上 pthread_detach(pthread_sel ...

  2. 设置Ubuntu 10.10版本的软件源

    设置Ubuntu 10.10版本的软件源 http://blog.csdn.net/xie1xiao1jun/article/details/49911189   网上有很多关于软件源信息的更新,每次 ...

  3. VMware Workstation 9.0 安装苹果Mac OS X10.9系统

    摘自:http://www.wuwenhui.cn/3133.html 一.安装所需要的软件: 1.VMware Workstation 9.0 点击下载 2.unlock-all-v110.zip  ...

  4. UTL_RAW

    The UTL_RAW package provides SQL functions for manipulating RAW data types. 该包的功能其实可以用来加密: SELECT    ...

  5. JAVA类(上)

    package test; public class staticAccess { public int age; public staticAccess grow() { age++; return ...

  6. asp.net后台对前台脚本的调用

    后台像前台输出要执行的脚本 Response.Write("<script>alert('内容')</script>"); asp.net后台调用前台js脚 ...

  7. Ubuntu Gnome下如何改动应用的图标icon

    我在我机器上安装了一个matlab,但在软件搜索里找不到matlab. 我发现是matlab没有相应的.desktop文件. 顺便我将matlab的图标也改动下.过程例如以下: 1.准备一个icon图 ...

  8. Resist the Temptation of the Singleton Pattern

    Resist the Temptation of the Singleton Pattern Sam Saariste THE SiNGLETON PATTERN SOLVES MANY OF YOU ...

  9. linux head命令

    head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾. 1.命令格式: hea ...

  10. Buenos Aires和Rio de Janeiro怎么发音?

    Buenos Aires和Rio de Janeiro怎么发音?_百度知道     Buenos Aires和Rio de Janeiro怎么发音?    2009-09-25 08:58 zd029 ...