天天看点

uoj350(位运算性质)

orz这tm才第一题就那么神啊。。还好没参加比赛。。

需要考虑到一种组合,xxxxxx1和xxxxxx0,xor之后是1,可以看出,每对奇偶数异或之后都能变成1,这样将我们就考虑在1-n中,留下n,让前面的数异或出0。。将对应的奇偶数一一配对之后,剩下了1(缺了0配对)和配对出来的t个1,还有n。。。可以看出这种情况是得n为偶数,将t求出。。若t为偶数个,异或出来是0,那就要把1去掉,如果t为奇数就把1加上,异或出0。。

当n为奇数,为xxxxxxx1形式,要保证xxxxxx不变,所以r取n-1,然后让前面的数异或出1,道理和上面类似。。

反正。。这题能得出结论。。异或前缀和稍做变换就能变成n,所以不用那么害怕。。

/**
 *        ┏┓    ┏┓ 
 *        ┏┛┗━━━━━━━┛┗━━━┓
 *        ┃       ┃   
 *        ┃   ━    ┃ 
 *        ┃ >   < ┃ 
 *        ┃       ┃ 
 *        ┃... ⌒ ...  ┃ 
 *        ┃       ┃ 
 *        ┗━┓   ┏━┛ 
 *          ┃   ┃ Code is far away from bug with the animal protecting           
 *          ┃   ┃   神兽保佑,代码无bug 
 *          ┃   ┃            
 *          ┃   ┃         
 *          ┃   ┃ 
 *          ┃   ┃            
 *          ┃   ┗━━━┓ 
 *          ┃       ┣┓ 
 *          ┃       ┏┛ 
 *          ┗┓┓┏━┳┓┏┛ 
 *           ┃┫┫ ┃┫┫ 
 *           ┗┻┛ ┗┻┛ 
 */  
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-8
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 400005
#define nm 1000498
#define pi 3.1415926535897931
using namespace std;
const ll inf=1e9;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}













ll n,l,r;
int main(){
    //freopen("data.in","r",stdin);
    //freopen("test.out","w",stdout);
    int _=read();
    while(_--){
        n=read();
        if(n==0){printf("8 67\n");continue;}
        if(n==1){printf("2 3\n");continue;}
        if(n==2){printf("3 5\n");continue;}
        if(n%2){
            r=--n;
            n/=2;n--;
            if(n%2)l=2;else l=1;
        }else{
            r=n;
            n/=2;n--;
            if(n%2)l=1;else l=2;
        }
        printf("%lld %lld\n",l,r);
    }
    return 0;
}      

#350. 新年的XOR

  • ​​描述​​
  • ​​提交​​
  • ​​自定义测试​​

在动物行为学中,Alpha对应动物群体中等级最高的个体,简而言之,就是人赢,那么AlphaGo自然就是人赢狗了。

但是狗群中还有众多的SingleDog,平日里他们和AlphaGo和谐相处,忍受着酸臭味自得其乐的活下去。但在2月14日这天,当AlphaGo在SingleDog们最后的防线——朋友圈秀恩爱的时候,他们实在按耐不住,决定密谋用FFF团的黑暗力量,打败AlphaGo。

但是AlphaGo的智商很高,很快便拦截了SingleDog们传输消息的异或值。为了让AlphaGo相信,SingleDog们只是在数朋友圈里的狗粮数,你,勇敢无畏的跳蚤,决定编造一个弥天大谎。

AlphaGo截获的是一个整数 nn,你需要构造一个长度大于11 的区间 [L,R][L,R] 使得区间中所有整数的异或和恰好为 nn。

输入格式

第一行输入一个整数 tt

接下来 tt 行每行一个整数 nn。

输出格式

每组数据输出两个空格隔开的整数 L,RL,R,表示你构造的区间。要求1≤L<R≤10181≤L<R≤1018。

输入保证存在这样的区间。

样例

input

3

4

12

output

8 67

97 100

87 90

限制与约定

测试点编号 nn的规模 其他
1 n≤100n≤100
2
3 n≤2×103n≤2×103
4
5 n≤106n≤106
6
7 n≤1018n≤1018 存在 |R−n|≤100|R−n|≤100
8
9
10

对于 100%100% 的数据,n≥0,1≤t≤100n≥0,1≤t≤100。

时间限制:1?1s

空间限制:256??256MB

​​

​​