codeforces 484a//Bits// Codeforces Round #276(Div. 1)
2024-08-24 19:19:26
题意:给出区间[ll,rr],求中间一个数二进制表示时一的个数最多。
写出ll和rr的二进制,设出现第一个不同的位置为pos(从高位到低位),找的数为x,那么为了使x在[ll,rr]内,前pos-1个位必须也相同。而rr在pos和pos后如果都为1,那么pos和pos后都取1,否则pos取0,pos后取1。
乱码:
//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <list>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
typedef long long lon;
const double EPS=1e-;
const lon one=; lon geth(lon x)
{
lon res=;
for(lon i=;i<;++i)
{
if(x&(one<<i))
{
res=max(res,i);
}
}
return res;
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
lon n;
cin>>n;
for(int i=;i<n;++i)
{
lon ll,rr;
cin>>ll>>rr;
lon bit=geth(rr);
lon res=;
for(lon j=bit;j>=;--j)
{
lon b1=rr&(one<<j);
lon b2=ll&(one<<j);
if(b1^b2)
{
lon cand=;
for(lon k=j;k>=;--k)
{
if(rr&(one<<k))++cand;
}
res+=(one<<max(j,cand))-;
break;
}
else res+=((one<<j)&rr);
}
cout<<res<<endl;
} return ;
}
最新文章
- Fragment的startActivityForResult和Activity的startActivityForResult的区别
- ros下多机器人系统(1)
- ubuntu中安装VMWare tools
- [日常训练]curves
- JAVA作业02
- 软件工程 speedsnail 第二次冲刺8
- PHP错误The server encountered an internal error or misconfiguration and was unable to complete your re
- Sqli-labs less 29
- Imageview使用记录
- Apache 目录权限
- SQL Server 表字段值转换成字段名称(二)
- mybatis关联查询,查询结果多条,却只返回一条记录
- VS Code 的常用快捷键
- ABP官方文档翻译 4.2 数据传输对象
- 搭建iSCSI文件服务器故障转移群集
- int 4 bytes
- pycharm换行
- python数据分析Titanic_Survived预测
- 什么是安全散列算法SHA256?
- Java中的volatile关键字为什么不是不具有原子性
热门文章
- VS2010的快捷键;VS2012变化的快捷键
- Java线程基础知识(状态、共享与协作)
- pycharm中内看内建函数的定义
- Linux基础命令---e2image
- Unity VR编辑器――如上帝般创建VR内容,Project Soli google用雷达识别手势体积相当于一张 Mini SD 内存卡
- Kali连接不上ssh
- dba和运维专家们说有丰富的大型分布式系统架构设计经验纯属扯淡
- troubleshooting-执行导数shell脚本抛异常error=2, No such file or directory
- 20145221《网络对抗》PC平台逆向破解
- Win32 实现 MFC CFileDialog 对话框