ZOJ - 4086: Little Sub and a Game (线性基 贪心) (占位)

Little Sub has another friend called lqybzx. One day, they are playing an interesting game.

In this game, there is a variable called "Justic Oops Heltion Attacks Neets Number" which is written as "JOHANN".

Initially, JOHANN is equal to . pairs of numbers () are given to Little Sub while pairs () are given to lqybzx.

Firstly, for every pair (), Little Sub will choose either or . Suppose he choose , JOHANN will be changed to (JOHANN ). ( denotes bitwise exclusive or)

After Little Sub's operations, lqybzx will do the same with his pairs.

They know about each other's pairs from the beginning.

Little Sub wishes the final value of JOHANN to be as great as possible while lqybzx wishes it to be as small as possible.

Little Sub and lqybzx are very clever boys and they will choose the best strategy. Can you predict the final value of JOHANN?

Input

There are multiple test cases. The first line of the input contains an integer (), indicating the number of test cases. For each test case:

The first line contains two integers and ().

Then lines follow. In each line, there are two integers (), representing Little Sub's pairs.

Then lines follow. In each line, there are two integers (), representing lqybzx's pairs.

Output

For each test case, you should output a single integer in a line as your answer.

Sample Input

2
1 1
6 3
4 1
2 2
1 3
4 6
5 4
2 2

Sample Output

2
2

Note

In the first sample, if Little Sub chooses , lqybzx will choose and the result will be .

If Little Sub chooses , lqybzx will choose and the result will also be .

Therefore the answer is .

题意:给定N对数(x,y)让Alice取,M对数让Bob取,取的规则的每对数选一个,得到异或和。 Alice先取完,得到X; 然后Bob来取,得到Y; 最终得到ans=X^Y;

A想要ans最大,B想要ans最小,问他们都采取最有措施,最后ans为多少。

思路:首先要完成一个转化,先让X=每对数的第一个数的异或和,那么规则就变为了对于没对数,是否取(x^y);

...后面的就是线性基来贪心了,还没仔细想。占个位

猜你喜欢

转载自www.cnblogs.com/hua-dong/p/10293426.html
今日推荐