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 ...
随机推荐
- kafka存储数据量过大,导致磁盘爆满
问题: 注意到自己负责kafka的某个topic最小的偏移量为0,而最大的偏移量都7亿多了,说明存储在kafka里面的数据没有定时删除,通过登陆到kafka服务器,查看配置文件services.pro ...
- shell字符串操作技巧
操作字符串 -------------- Bash支持超多的字符串操作,操作的种类和数量令人惊异.但不幸的是,这些工具缺乏集中性. 一些是参数替换的子集,但是另一些则属于UNIX的expr命令.这就导 ...
- Servlet过滤器和监听器配置范例
1,Servlet过滤器 <filter> <filter-name>charset</filter-name> <filter-class>org.g ...
- Quartz框架调用Demo
Quartz框架调用Demo 任务调度在JAVA应用程序中运用的十分普遍,掌握QUARTZ是必备的技能; 官网:http://www.quartz-scheduler.org/ 下载最新1.80资源包 ...
- 安装webpack出现警告: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
警告如下: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_mo ...
- Starting MySQL...The server quit without updating PID file [失败]local/mysql/data/localhost.localdomain.pid报错
在添加命令自动补全的时候mysql启动失败 这是原配 # For advice on how to change settings please see # http://dev.mysql.com/ ...
- 20145330 《网络对抗》 Eternalblue(MS17-010)漏洞复现与S2-045漏洞的利用及修复
20145330 <网络对抗> Eternalblue(MS17-010)漏洞利用工具实现Win 7系统入侵与S2-045漏洞的利用及修复 加分项目: PC平台逆向破解:注入shellco ...
- 0x30、0x37
1.write_date(0x30+shi)加0x30是什么意思 答: 将数字0-9转化为字符'0'-'9' 1.write_date(0x37+bai)加0x37是什么意思 答: 将大于9的数字转化 ...
- js实现ajax请求
练下手,好久没写ajax var xmlhttp=null;//创建XMLHttprequest function createXMLHttpRequest(){ if(window.ActiveXO ...
- Linxu内核版本号后面多出字符串或者+号【学习笔记】
作者:庄泽彬 之前一直没有留意到但是最近在编译内核的时候版本号竟然多出了个加号+号或字符串, 后面终于找到原因了,原来config如果设置了CONFIG_LOCALVERSION_AUTO=y,内核的 ...