Codeforces Round #276 (Div. 2) C
来源:互联网 发布:软件创新之路 编辑:程序博客网 时间:2024/05/22 06:56
C. Bits
题意:在一个区间[l,r]内找出二进制下"1"最多的数,如果有多解,输出最小的数。
思路:贪心。从l开始,从低位到高位,逐位或1,如果或结果不比r大,就或上去。
#include<cstdio>#include<iostream>#include<algorithm>using namespace std;#define ll long longint main(){int t;cin>>t;while(t--){ll l,r;cin>>l>>r;ll cur=l;ll tmp=1;while(tmp<r){if((cur|tmp)<=r)cur|=tmp;tmp<<=1;}cout<<cur<<endl;}return 0;}
0 0
- Codeforces Round #276 (Div. 2) C
- Codeforces Round #276 (Div. 2) C. Bits
- Codeforces Round #276 (Div. 2)(C)
- Codeforces Round #276 (Div. 2)-C. Bits
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #276 (Div. 2)
- Codeforces Round #276 (Div. 2)
- Codeforces Round #276(Div. 2)
- Codeforces Round #276 (Div. 2)
- Codeforces Round #276 (Div. 2)
- Codeforces Round #276 (Div. 2)
- Codeforces Round #276 (Div. 2) A B C D
- Codeforces Round #276 (Div. 2)(C贪心,D)
- 【瞎搞】 Codeforces Round 276 DIV 2 C.Bits
- Codeforces Round #276 (Div. 2) C. Bits (想法)
- Codeforces Round #276 (Div. 2) C. Bits 二进制
- Codeforces Round #105 (Div. 2) C
- Codeforces Round 134 div 2 C题
- Android UI布局之TableLayout
- Mac和iOS开发资源汇总
- Mac OS X 软件包管理器 – Homebrew
- /system/app apk裁剪
- android 横向滚动文字的实现
- Codeforces Round #276 (Div. 2) C
- 钢板桩在国外的应用概况
- get与post提交方式的区别
- SqlServerCE数据库类(转自http://blog.csdn.net/letian_fly/article/details/2975962)
- Android下拉刷新完全解析,教你如何一分钟实现下拉刷新功能
- socket 错误码errno
- nyoj814又见拦截导弹
- mysql函数收集
- poj 2353 双向dp(麻烦的办公室盖章)