首页 > 其他分享 >CF 254A(重复的数)

CF 254A(重复的数)

时间:2022-10-25 11:07:37浏览次数:43  
标签:q1 q2 卡片 重复 CF 254A output input size


A. 数字卡片



time limit per test



memory limit per test



input



output



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



Input



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



Output



-1.否则输出 n

输出任意方案。



Sample test(s)



input



3 20 30 10 30 20 10



output



4 2 1 5 6 3



input



1 1 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.



标签:q1,q2,卡片,重复,CF,254A,output,input,size
From: https://blog.51cto.com/u_15724837/5794136

相关文章