A. Cards with Numbers

来源:互联网 发布:百龄洁牙粉 知乎 编辑:程序博客网 时间:2024/04/29 16:00

time limit per test
1 second
memory limit per test
256 megabytes
input
input.txt
output
output.txt

Petya has got 2n cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2n. We'll denote the number that is written on a card with number i, as ai. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.

Input

The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains the sequence of 2n positive integersa1, a2, ..., a2n (1 ≤ ai ≤ 5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.

Output

If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer-1. But if the required partition exists, then print n pairs of integers, a pair per line — the indices of the cards that form the pairs.

Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.

Sample test(s)
input
320 30 10 30 20 10
output
4 21 56 3
input
11 2
output
-1

解题说明:此题就是给定一列数字,看能不能均分为两等份。可以先对数字进行排序,保证大小不同的数字出现偶数次,为了记录下标,用一个pair来保存比较方便。

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include<set>#include <algorithm>using namespace std;pair<int ,int > a[600100];int n,i;int main(){freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);cin>>n;for( i=1; i<=2*n; i++){cin>>a[i].first; a[i].second=i; }sort(a+1,a+n*2+1);for( i=1; i<=n*2; i+=2){if (a[i].first!=a[i+1].first){cout<<-1<<endl; return 0;}}for( i=1; i<=n*2; i+=2){cout<<a[i+1].second<<' '<<a[i].second<<endl;}}


原创粉丝点击