Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

Problem Description
Bit operation is a common computing method in computer science ,Now we have two positive integers A and B ,Please find a positive integer C that minimize the value of the formula (A xor C) & (B xor C) .Sometimes we can find a lot of C to do this ,So you need to find the smallest C that meets the criteria .

For example ,Let's say A is equal to 5 and B is equal to 3 ,we can choose C =1,3.... ,so the answer we're looking for C is equal to 1.

If the value of the expression is 0 when C=0, please print 1.

Input
The input file contains T test samples.(1<=T <=100)

The first line of input file is an integer T .

Then the T lines contains 2 positive integers, A and B , (1≤A,B<232 )

Output
For each test case,you should output the answer and a line for each answer.

Sample Input
1 3 5

Sample Output
1

 
 
签到题qwq
AB同位均为1时异或为0,其余不管。
注意C为正整数,故若C0则令其为1
 
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #define MIN(a,b) (a)<(b)?(a):(b)
 5 #define MAX(a,b) (a)>(b)?(a):(b)
 6 #define ABS(a) (a)>0?(a):-(a)
 7 #define fo(i,a,b) for (int i=(a);i<=(b);++i)
 8 #define fod(i,a,b) for (int i=(a);i>=(b);--i)
 9 #define rep(i,a,b) for (int i=(a);i<(b);++i)
10 #define repd(i,a,b) for (int i=(a);i>(b);--i)
11 typedef long long LL;
12 using namespace std;
13 LL a,b,c;
14 int t,cnt;
15 void readint(int &x){
16     x=0;
17     int w=1;
18     char c;
19     for (c=getchar();c<'0'||c>'9';c=getchar()) if (c=='-') w=-1;
20     for (;c>='0'&&c<='9';c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
21     x*=w; 
22 }
23 void readlong(LL &x){
24     x=0;
25     LL w=1;
26     char c;
27     for (c=getchar();c<'0'||c>'9';c=getchar()) if (c=='-') w=-1;
28     for (;c>='0'&&c<='9';c=getchar()) x=(x<<3)+(x<<1)+(c^'0');
29     x*=w; 
30 }
31 int main(){
32     readint(t);
33     while (t--){
34         readlong(a);
35         readlong(b);
36         cnt=0;
37         c=0;
38         while (a>0&&b>0){
39             if ((a&1)&&(b&1)) c+=(1LL<<cnt);
40             ++cnt;
41             a>>=1;
42             b>>=1;
43         }
44         if(c==0)++c;
45         printf("%lld\n",c);
46     }
47     return 0;
48 }
神奇的代码

 

array (HDU 6703)

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)

Problem Description
You are given an array a1,a2,...,an(∀i∈[1,n],1≤ai≤n) . Initially, each element of the array is **unique**.

Moreover, there are m instructions.

Each instruction is in one of the following two formats:

1. (1,pos) ,indicating to change the value of apos to apos+10,000,000 ;
2. (2,r,k) ,indicating to ask the minimum value which is **not equal** to any ai ( 1≤i≤r ) and **not less ** than k .

Please print all results of the instructions in format 2 .


Input
The first line of the input contains an integer T(1≤T≤10) , denoting the number of test cases.

In each test case, there are two integers n(1≤n≤100,000) ,m(1≤m≤100,000) in the first line, denoting the size of array a and the number of instructions.

In the second line, there are n distinct integers a1,a2,...,an (∀i∈[1,n],1≤ai≤n) ,denoting the array.
For the following m lines, each line is of format (1,t1) or (2,t2,t3) .
The parameters of each instruction are generated by such way :

For instructions in format 1 , we defined pos=t1⊕LastAns . (It is promised that 1≤pos≤n )

For instructions in format 2 , we defined r=t2⊕LastAns,k=t3⊕LastAns . (It is promised that 1≤r≤n,1≤k≤n )

(Note that ⊕ means the bitwise XOR operator. )

Before the first instruction of each test case, LastAns is equal to 0 .After each instruction in format 2 , LastAns will be changed to the result of that instruction.

(∑n≤510,000,∑m≤510,000 )

Output
For each instruction in format , output the answer in one line.
 
Sample Input
3

5 9
4 3 1 2 5
2 1 1
2 2 2
2 6 7
2 1 3
2 6 3
2 0 4
1 5
2 3 7
2 4 3
10 6
1 2 4 6 3 5 9 10 7 8
2 7 2
1 2
2 0 5
2 11 10
1 3
2 3 2
10 10
9 7 5 3 4 10 6 2 1 8
1 10
2 8 9
1 12
2 15 15
1 12
2 1 3
1 9
1 12
2 2 2
1 9

 
Sample Output

1
5
2
2
5
6
1
6
7
3
11
10
11
4
8
11


Hint

note:
After the generation procedure ,the instructions of the first test case are :
2 1 1, in format 2 and r=1 , k=1
2 3 3, in format 2 and r=3 , k=3
2 3 2, in format 2 and r=3 , k=2
2 3 1, in format 2 and r=3 , k=1
2 4 1, in format 2 and r=4 , k=1
2 5 1, in format 2 and r=5 , k=1
1 3 , in format 1 and pos=3
2 5 1, in format 2 and r=5 , k=1
2 5 2, in format 2 and r=5 , k=2

the instructions of the second test case are :
2 7 2, in format 2 and r=7 , k=2
1 5 , in format 1 and pos=5
2 7 2, in format 2 and r=7 , k=2
2 8 9, in format 2 and r=8 , k=9
1 8 , in format 1 and pos=8
2 8 9, in format 2 and r=8 , k=9

the instructions of the third test case are :
1 10 , in format 1 and pos=10
2 8 9 , in format 2 and r=8 , k=9
1 7 , in format 1 and pos=7
2 4 4 , in format 2 and r=4 , k=4
1 8 , in format 1 and pos=8
2 5 7 , in format 2 and r=5 , k=7
1 1 , in format 1 and pos=1
1 4 , in format 1 and pos=4
2 10 10, in format 2 and r=10 , k=10
1 2 , in format 1 and pos=2

相关文章:

  • 2022-12-23
  • 2021-08-05
  • 2022-12-23
  • 2022-12-23
  • 2021-10-04
  • 2021-11-26
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-19
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2021-07-08
相关资源
相似解决方案