Senha do intervalo do coelho NC20860 (pergunta de conclusão)

https://ac.nowcoder.com/acm/problem/20860

Solução: Os dígitos binários do valor XOR em ambas as extremidades do intervalo devem ser o dígito do valor máximo, então alteramos todos os valores dos dígitos binários para 1.

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <utility>
#include <queue>
#include <map>
#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int maxn=1e5+5;
void io() { ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); }
inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}

inline void write(int x)
{	//不能输出0 
    char F[200];
    int tmp=x>0?x:-x ;
    if(x<0)putchar('-') ;
    int cnt=0 ;
       while(tmp>0)
       {
           F[cnt++]=tmp%10+'0';
           tmp/=10;
       }
       while(cnt>0)putchar(F[--cnt]) ;
}

signed main() {
	int test=1; test=read();
	
	while(test--) {
		int l,r;
		l=read();r=read();
		ll t=l^r,ans=0;
		while(t) {
			ans=ans*2+1;
			t>>=1;
		} 
		printf("%lld\n",ans);
	}



}

 

Acho que você gosta

Origin blog.csdn.net/qq_44132777/article/details/107707565
Recomendado
Clasificación