Codeforces Round #456 (Div. 2)

A. Tricky Alchemy

签到


B. New Year's Eve

题意

给定两个整数nk:在1~n中选择至多k个整数,使得其异或和最大。求解这个最大值(1<=n,k<=1e18)

分析

注意k=1的情况

其他都为能取到的最大值

#include<bits/stdc++.h>
#define ll unsigned long long
using namespace std;

#define mz 1000000007
#define pq priority_queue

ll n,k;

int main()
{
    scanf("%lld%lld", &n, &k);
    ll sum=1;
    int ans=0;
    for(int i=0;i<200;i++)
    {
        sum=(1ll<<i);
        //cout<<sum<<endl;
        if(sum>n)
        {
            ans=i;
            break;
        }
    }
    //cout<<ans<<endl;
    if(k==1)
    {
        printf("%lld
", n);
    }
    else
    {
        sum=0;
        for(int i=ans-1;i>=0;i--)
        {
           sum+=(1ll<<i);
        }
        printf("%lld
", sum);
    }
    return 0;
}
View Code

 C. Perun, Ult!

题意

分析


 D. Fishes

题意

分析


E. Prime Gift

题意

分析

要么优秀要么生锈
原文地址:https://www.cnblogs.com/Superwalker/p/8241647.html