zoukankan      html  css  js  c++  java
  • Codeforces Round #456 (Div. 2) B. New Year's Eve

    B. New Year's Eve

    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

    Examples

    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);
        else
        {
            ll r=0;
            while(n)n>>=1,r=r<<1|1;
            printf("%lld
    ",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+10;
    vector<int>Q[maxn];
    const int MOD=1e9+7;
    LL lev[65],sta[65];
    void pre()
    {
        Rep(i,62) lev[i]=(1LL<<i)-1;
        sta[0]=1;
        REP(i,61) sta[i]=sta[i-1]<<1;
        Rep(i,62) lev[62]+=sta[i];
    }
    
    int main()
    {
        FastRead;
        LL k,n;
        pre();
        cin>>n>>k;
            if(k==1) cout<<n<<endl;
            else
            {
                for(int i=0;i<=61;i++)
                    if(n>=lev[i]&&n<=lev[i+1])
                    {
                        cout<<lev[i+1]<<endl;
                        break;
                    }
            }
    
        return 0;
    }
    View Code
  • 相关阅读:
    【HICP Gaussdb】数据库 数据库管理( 导入 导出 闪回 调优 wsr报告 ) -13
    【Flask项目】 python学习第一章
    【Flask项目】 python学习第一章
    【HICP Gaussdb】数据库 数据库管理( 备份 导入 导出 ) -12
    【系统级配置】/etc/sysctl.conf
    【Flask项目】 python学习第一章
    【HICP Gaussdb】数据库 数据库管理( 数据库安全 账户 日志管理)-11
    【Git】 python学习第一章
    【HICP Gaussdb】数据库 数据库管理(并发 锁 数据库安全)-10
    【HCIA Gauss】学习汇总-数据库管理(三范式 GAUSSDB100)-8
  • 原文地址:https://www.cnblogs.com/weimeiyuer/p/8214708.html
Copyright © 2011-2022 走看看