Codeforces Round #456 (Div. 2) B. New Year's Eve
B. New Year's Eve
1 second
256 megabytes
standard input
standard output
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains n sweet candies from the good ol' bakery, each labeled from 1 to n corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a direct effect on Grisha's happiness. One can assume that he should take the tastiest ones — but no, the holiday magic turns things upside down. It is the xor-sum of tastinesses that matters, not the ordinary sum!
A xor-sum of a sequence of integers a1, a2, ..., am is defined as the bitwise XOR of all its elements: , here
denotes the bitwise XOR operation; more about bitwise XOR can be found here.
Ded Moroz warned Grisha he has more houses to visit, so Grisha can take no more than k candies from the bag. Help Grisha determine the largest xor-sum (largest xor-sum means maximum happiness!) he can obtain.
Input
The sole string contains two integers n and k (1 ≤ k ≤ n ≤ 1018).
Output
Output one number — the largest possible xor-sum.
Input
4 3
Output
7
Input
6 6
Output
7
Note
In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7.
一眼题,当k为1输出本身,k不为1时,要让异或最大,则最高位以下(包括最高位)的的二进制全为1,或者像我第一反应一样打表2333(蠢哭)...
正常代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n,k;
scanf("%lld%lld",&n,&k);
if(k==1)printf("%lld\n",n);
else
{
ll r=0;
while(n)n>>=1,r=r<<1|1;
printf("%lld\n",r);
}
return 0;
}
蠢哭代码:
#include<bits/stdc++.h>
//******************************************************
#define lrt (rt*2)
#define rrt (rt*2+1)
#define LL long long
#define inf 0x3f3f3f3f
#define pi acos(-1.0)
#define exp 1e-8
//***************************************************
#define eps 1e-8
#define inf 0x3f3f3f3f
#define INF 2e18
#define LL long long
#define ULL unsigned long long
#define PI acos(-1.0)
#define pb push_back
#define mk make_pair #define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SQR(a) ((a)*(a))
#define Unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define Iterator(a) __typeof__(a.begin())
#define rIterator(a) __typeof__(a.rbegin())
#define FastRead ios_base::sync_with_stdio(0);cin.tie(0)
#define CasePrint pc('C'); pc('a'); pc('s'); pc('e'); pc(' '); write(qq++,false); pc(':'); pc(' ')
#define vi vector <int>
#define vL vector <LL>
#define For(I,A,B) for(int I = (A); I < (B); ++I)
#define FOR(I,A,B) for(int I = (A); I <= (B); ++I)
#define rFor(I,A,B) for(int I = (A); I >= (B); --I)
#define Rep(I,N) For(I,0,N)
#define REP(I,N) FOR(I,1,N)
using namespace std;
const int maxn=1e5+;
vector<int>Q[maxn];
const int MOD=1e9+;
LL lev[],sta[];
void pre()
{
Rep(i,) lev[i]=(1LL<<i)-;
sta[]=;
REP(i,) sta[i]=sta[i-]<<;
Rep(i,) lev[]+=sta[i];
} int main()
{
FastRead;
LL k,n;
pre();
cin>>n>>k;
if(k==) cout<<n<<endl;
else
{
for(int i=;i<=;i++)
if(n>=lev[i]&&n<=lev[i+])
{
cout<<lev[i+]<<endl;
break;
}
} return ;
}
Codeforces Round #456 (Div. 2) B. New Year's Eve的更多相关文章
- Codeforces Round #456 (Div. 2) B. New Year's Eve
传送门:http://codeforces.com/contest/912/problem/B B. New Year's Eve time limit per test1 second memory ...
- Codeforces Round #456 (Div. 2)
Codeforces Round #456 (Div. 2) A. Tricky Alchemy 题目描述:要制作三种球:黄.绿.蓝,一个黄球需要两个黄色水晶,一个绿球需要一个黄色水晶和一个蓝色水晶, ...
- Codeforces Round #456 (Div. 2) A. Tricky Alchemy
传送门:http://codeforces.com/contest/912/problem/A A. Tricky Alchemy time limit per test1 second memory ...
- Codeforces Round #456 (Div. 2) 912E E. Prime Gift
题 OvO http://codeforces.com/contest/912/problem/E 解 首先把这个数字拆成个子集,各自生成所有大小1e18及以下的积 对于最坏情况,即如下数据 16 2 ...
- Codeforces Round #456 (Div. 2) 912D D. Fishes
题: OvO http://codeforces.com/contest/912/problem/D 解: 枚举每一条鱼,每放一条鱼,必然放到最优的位置,而最优位置即使钓上的概率最大的位置,即最多的r ...
- 【Codeforces Round #456 (Div. 2) A】Tricky Alchemy
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 统计需要的个数. 不够了,就买. [代码] #include <bits/stdc++.h> #define ll lo ...
- 【Codeforces Round #456 (Div. 2) B】New Year's Eve
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然10000..取到之后 再取一个01111..就能异或成最大的数字了. [代码] /* 1.Shoud it use long ...
- 【Codeforces Round #456 (Div. 2) C】Perun, Ult!
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] set1 < pair < int,int > > set1;记录关键点->某个人怪物永远打不死了,第 ...
- Codeforces Round #456 (Div. 2) B题
B. New Year's Evetime limit per test1 secondmemory limit per test256 megabytesinputstandard inputout ...
随机推荐
- Linux的crontab应注意事项
今天遇到一个问题,困扰了好久,刚开始时以为crontab定时任务配置错误,后经过验证没有错误,然后又怀疑到是不是权限问题呀?将权限跟改为root后,重新配置crontab定时任务,还是不行,真是让人气 ...
- svn一次性add/delete所有文件
Linux命令行下,svn add 一次性批量上传 命令行下操作svn没有使用界面形式的TortoiseSVN直观,但是不管怎样,命令行下操作svn还是有它的有点,如果你碰到一次需要svn add许多 ...
- 客户关系管理系统CRM
http://www.cnblogs.com/Michael2397/tag/SSH%E9%A1%B9%E7%9B%AE-CRM/ 客户关系管理系统
- 小X归来 模拟赛1 解析
Problem1 单峰 小X 归来后,首先对数列很感兴趣.他想起有1类特殊的数列叫单峰数列. 我们说一个数列 {ai} 是单峰的,当且仅当存在一个位置 k 使得 ai < ai+1(i < ...
- 前后台交互(打开前端页面,不传递任何数据,发送ajax请求)
1.打开前端,不传递任何数据 <script src="./jquery.min.js"></script> <script> $(docume ...
- Laravel + Vue 之 OPTIONS 请求的处理
问题: 在 Vue 对后台的请求中,一般采用 axios 对后台进行 Ajax 交互. 交互发生时,axios 一般会发起两次请求,一次为 Options 试探请求,一次为正式请求. 由此带来的问题是 ...
- vertical-align和text-align
vertical-align只适用于内联元素. 垂直对齐:vertical-align属性(转) 行高与单行纯文字的垂直居中,而如果行内含有图片和文字,在浏览器内浏览时,读者可以发现文字和图片在垂直方 ...
- 2018.09.05 bzoj2726: [SDOI2012]任务安排(斜率优化dp+二分)
传送门 跟Ti" role="presentation" style="position: relative;">TiTi为正数的时候差不多. ...
- spring boot2.0冷知识
首先,Spring Boot 2.0.0 要求 Java 8 或更高版本,不再支持 Java 6 和 7. 在 Spring Boot 2.0 中,许多配置属性已被重命名或被删除,相应地,开发者需要升 ...
- day15(mysql 的多表查询,事务)
mysql之多表查询 1.合并结果集 作用:合并结果集就是把两个select语句查询的结果连接到一起! /*创建表t1*/ CREATE TABLE t1( a INT PRIMARY KEY , b ...