【瞎搞】 Codeforces 460D Little Victor and Set 位运算构造

本文通过一个具体的编程实例展示了如何使用位运算和逻辑判断来解决问题。针对不同的条件,采用位操作来快速判断并输出相应的解决方案,对于理解位运算的应用场景及逻辑判断的技巧有很好的示范作用。

点击打开链接

L^L==0



L为偶数时

L^(L+1)^(L+2)^(L+3)==0

L^(L+1)==1


#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cmath>
using namespace std;
#include <queue>
#include <stack>
#include <vector>
#include <deque>
#include <set>
#include <map>
#define cler(arr, val)    memset(arr, val, sizeof(arr))
typedef long long  LL;
const int MAXN = 150100;
const int MAXM = 11111;
const int INF = 0x3f3f3f3f;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int main()
{
    LL l,r,k;
    cin>>l>>r>>k;
    if(k>=4)
    {
        if((l&1)&&(r-l)>=4)
        {
            cout<<0<<endl;
            cout<<4<<endl;
            cout<<l+1<<" "<<l+2<<" "<<l+3<<" "<<l+4<<endl;
            return 0;
        }
        else if(!(l&1))
        {

            cout<<0<<endl;
            cout<<4<<endl;
            cout<<l<<" "<<l+1<<" "<<l+2<<" "<<l+3<<endl;
            return 0;
        }
    }
    if(k>=3)
    {
        LL tol=0,tp=l;
        while(tp)
        {
            tp>>=1;
            ++tol;
        }
        tp=(LL)3<<(tol-1);
        if(tp<=r)
        {
            cout<<0<<endl;
            cout<<3<<endl;
            cout<<tp<<" "<<l<<" "<<(tp^l)<<endl;
            return 0;
        }
    }
    if(k>=2)
    {
        if((l&1) && r-l>=2)
        {
            cout<<1<<endl;
            cout<<2<<endl;
            cout<<l+1<<" "<<l+2<<endl;
            return 0;
        }
        else if(!(l&1))
        {
            cout<<1<<endl;
            cout<<2<<endl;
            cout<<l<<" "<<l+1<<endl;
            return 0;
        }
        else if((l^r)<l)
        {
            cout<<(l^r)<<endl;
            cout<<2<<endl;
            cout<<l<<" "<<r<<endl;
            return 0;
        }
    }
    if(k>=1)
    {
        cout<<l<<endl;
        cout<<1<<endl;
        cout<<l<<endl;
        return 0;
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值