CF 254A(重复的数)

来源:互联网 发布:男科网络推广 编辑:程序博客网 时间:2024/05/21 08:39
A. 数字卡片
time limit per test
1 second
memory limit per test
256 megabytes
input
input.txt
output
output.txt

2n张卡片编号为1 .. 2n.卡片数字相同可凑成一对,能否凑完?

Input

第一行1个整数n (1 ≤ n ≤ 3·105). 第二行有2n个整数a1, a2, ..., a2n (1 ≤ ai ≤ 5000) 表示第i张卡片的数字。

Output

如果凑不完,请输出 -1.否则输出 n 行,每行一对对整数,表示第i张卡片与第j张凑成一对。

输出任意方案。

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


直接用数组记录出现次数,每遇到一对,就扔入解中。

Program Cards;const   maxn=300000;var   n,i,p,size:longint;   a:array[1..5000] of longint;   q1,q2:array[1..maxn] of longint;begin   assign(input,'input.txt');   assign(output,'output.txt');   reset(input);   rewrite(output);   read(n);   fillchar(a,sizeof(a),0);   size:=1;   for i:=1 to 2*n do   begin      read(p);      if a[p]>0 then      begin         q1[size]:=a[p];q2[size]:=i;         inc(size);         a[p]:=0;      end      else a[p]:=i;   end;   if size<>n+1 then writeln('-1')   else for i:=1 to n do writeln(q1[i],' ',q2[i]);   close(input);   close(output);end.


原创粉丝点击