codeforces 484a//Bits// Codeforces Round #276(Div. 1)
题意:给出区间[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 ;
}
codeforces 484a//Bits// Codeforces Round #276(Div. 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 ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- C. Bits (Codeforces Round #276 (Div. 2) )
题目大意:给你两个数l,r(l<r),求一个数是大于等于l且小于等于r的数中二进制数的1的个数最多,如果1的个数相同则取最小的那个(翻译渣,请见谅!) 思路:把左区间L化为二进制,再把左区间的二 ...
- 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 ...
- Codeforces Round #276 (Div. 2)C. Bits(构造法)
这道题直接去构造答案即可. 对于l的二进制表示,从右到左一位一位的使其变为1,当不能再变了(再变l就大于r了)时,答案就是l. 这种方法既可以保证答案大于等于l且小于等于r,也可以保证二进制表示时的1 ...
- Codeforces Round #276 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/485 A题.Factory 模拟.判断是否出现循环,如果出现,肯定不可能. 代码: #include<cstdio> ...
- Codeforces Round #276 (Div. 1) E. Sign on Fence (二分答案 主席树 区间合并)
链接:http://codeforces.com/contest/484/problem/E 题意: 给你n个数的,每个数代表高度: 再给出m个询问,每次询问[l,r]区间内连续w个数的最大的最小值: ...
- Codeforces Round #276 (Div. 1) D. Kindergarten dp
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/proble ...
- Codeforces Round #276 (Div. 1) B. Maximum Value 筛倍数
B. Maximum Value Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/484/prob ...
随机推荐
- SQL语句--查询任务
SELECT 目标字段1, 目标字段2 FROM 目标表WHERE ID IN(SELECT 外键 FROM 外键所在表WHERE 提供数据字段 IN(提供数据第一条, 提供数据第二条, ))
- quartz开源作业调度框架的配置
quartz开源作业调度框架的job服务实现,Quartz是一个完全由java编写的开源作业调度框架,使用时候需要创建一个实现org.quartz.Job接口的java类,Job接口包含唯一的方法: ...
- Applying the Kappa architecture in the telco industry
https://www.oreilly.com/ideas/applying-the-kappa-architecture-in-the-telco-industry Kappa architectu ...
- python之路----logging模块
函数式简单配置 import logging logging.debug('debug message') #bug logging.info('info message') #信息 logging. ...
- WebSocket协议详解
转自 http://www.cnblogs.com/lizhenghn/p/5155933.html 1. websocket 是什么 websocket 是html5提出的一个协议规范,参考rfc6 ...
- 使用requireJS加载不符合AMD规范的js文件:shim的使用方式和实现原理
原文链接: http://www.bubuko.com/infodetail-671521.html
- 20145310《网络对抗》逆向及Bof基础
实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任何用户输入的字符串. 该程序同时包含另一个代码片段,getShe ...
- 20145331魏澍琛《网络对抗》逆向及Bof基础
20145331魏澍琛<网络对抗>逆向及Bof基础 实践目标 本次实践的对象是一个名为pwn1的linux可执行文件. 该程序正常执行流程是:main调用foo函数,foo函数会简单回显任 ...
- android 通过webview调起支付宝app支付
网站学习:http://blog.csdn.net/zhuyu19911016520/article/details/71763900
- Bootstrap 使用教程 与jQuery的Ajax方法
jQuery.ajax(url,[settings]) 更加详细的内容参考 jQuery API 中文在线手册 概述 通过 HTTP 请求加载远程数据. jQuery 底层 AJAX 实现.简单 ...