题目
给定两个集合A、B,集合内的任一元素x满足1 ≤ x ≤ 109,并且每个集合的元素个数不大于105。我们希望求出A、B之间的关系。
任 务 :给定两个集合的描述,判断它们满足下列关系的哪一种:
A是B的一个真子集,输出“A is a proper subset of B”
B是A的一个真子集,输出“B is a proper subset of A”
A和B是同一个集合,输出“A equals B”
A和B的交集为空,输出“A and B are disjoint”
上述情况都不是,输出“I’m confused!”
题解
只要判断B里有多少数在A中存在,然后根据答案进行判断并输出
用Hash表,然后尽可能的把Hash开大以换时间
最后对答案的判断也要注意一下
代码
超时
const
d=10000007;
var
a:array[0..d]of longint;
n,m,i,j,k,ans:longint;
function locate(x:longint):longint;
var
i:longint;
begin
i:=x mod d;
while (a[i]<>x)and(a[i]<>0) do
i:=(i+1) mod d;
locate:=i;
end;
begin
read(n);
for i:=1 to n do
begin
read(j);
k:=locate(j);
if a[k]=0 then a[k]:=j;
end;
read(m);
for i:=1 to m do
begin
read(j);
k:=locate(j);
if a[k]=j then inc(ans);
end;
if (ans=n)and(n=m) then writeln('A equals B') else
if (ans=n)and(n<m) then writeln('A is a proper subset of B') else
if (ans=m)and(n>m) then writeln('B is a proper subset of A') else
if ans=0 then writeln('A and B are disjoint') else
writeln('I','''','m confused!');
end.