Codeforces Round #270 F(高斯消元+XOR)

F. Design Tutorial: Change the Goal
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are some tasks which have the following structure: you are given a model, and you can do some operations, you should use these operations to achive the goal. One way to create a new task is to use the same model and same operations, but change the goal.

Let's have a try. I have created the following task for Topcoder SRM 557 Div1-Hard: you are given n integers x1, x2, ..., xn. You are allowed to perform the assignments (as many as you want) of the following form xi ^= xj (in the original task i and j must be different, but in this task we allow i to equal j). The goal is to maximize the sum of all xi.

Now we just change the goal. You are also given n integers y1, y2, ..., yn. You should make x1, x2, ..., xn exactly equal to y1, y2, ..., yn. In other words, for each i number xi should be equal to yi.

Input

The first line contains an integer n (1 ≤ n ≤ 10000). The second line contains n integers: x1 to xn (0 ≤ xi ≤ 109). The third line contains n integers: y1 to yn (0 ≤ yi ≤ 109).

Output

If there is no solution, output -1.

If there is a solution, then in the first line output an integer m (0 ≤ m ≤ 1000000) – the number of assignments you need to perform. Then print m lines, each line should contain two integers i and j (1 ≤ i, j ≤ n), which denote assignment xi ^= xj.

If there are multiple solutions you can print any of them. We can prove that under these constraints if there exists a solution then there always exists a solution with no more than 106 operations.

Sample test(s)
input
2
3 5
6 0
output
2
1 2
2 2
input
5
0 0 0 0 0
1 2 3 4 5
output
-1
input
3
4 5 6
1 2 3
output
5
3 1
1 2
2 2
2 3
3 1
input
3
1 2 3
4 5 6
output
-1

题意:RT

思路:首先注意交换两个数a和b的值可以 a^=b b^=a a^=b

            然后将a序列的每个数都可以看成一个方程,方程的系数可以看成1或0,因为这个数不会超过10^9,也就是30位,最多30个1或0

            那么a序列的n个数就是n个方程组,用高斯消元解即可

            b序列用与a同样的方法化简即可,然后比较a和b序列是不是一样的,如果不一样则a不可能变化得到b

            然后a要从原始序列变到b,只需要先变到高斯消元得到的最简序列,然后再逆变化到b的原始序列(b和a的最简序列是一样的,xor运算也是可逆的)

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
#define pii pair
const int MAXN = 10010;
int a[MAXN];
int b[MAXN];
int n;
vectorqa,qb;

void Xor(int *a,int i,int j,vector &q)
{
    q.push_back(make_pair(i,j));
    a[i]^=a[j];
}

void guass(int *a,vector &q)
{
    int p=0;
    for(int i=29;i>=0;i--){
        for(int j=p;j>=1;
        for(int j=0;j<30&&j
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值