SSL_1125 合集

来源:互联网 发布:淘宝手机上购物支付 编辑:程序博客网 时间:2024/06/05 19:45

Description

给定两个集合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!”

Input

输入有两行,分别表示两个集合,每行的第一个整数为这个集合的元素个数(至少一个),然后紧跟着这个集合的元素(均为不同的正整数)

Output

只有一行,就是A、B的关系。

Sample Input

样例1
2 55 27
2 55 27
样例2
3 9 24 1995
2 9 24
样例3
3 1 2 3
4 1 2 3 4
样例4
3 1 2 3
3 4 5 6
样例5
2 1 2
2 2 3

哈希表
注意函数的值和哈希数组的大小,都尽量大一些
最后就是末尾的if判断要注意一些小问题
其他就是一个标准哈希就好了

Sample Output

样例1
A equals B
样例2
B is a proper subset of A
样例3
A is a proper subset of B
样例4
A and B are disjoint
样例5
I’m confused!

var a,b,h:array[0..1000001]of longint; i,j,n,sum,t,empty,nn,max,key,wz:longint;function locate(x:longint):longint;var j,wz:longint;begin wz:=x mod key; j:=0; while (h[wz+j]<>0)and(h[(wz+j)mod key]<>x) do  inc(j); locate:=wz+j;end;begin read(n); for i:=1 to n do  read(a[i]); read(nn); for i:=1 to nn do  read(b[i]); {empty:=maxlongint; for i:=0 to 100009 do  h[i]:=empty;} key:=1000000; for i:=1 to n do   begin     wz:=locate(a[i]);     h[wz]:=a[i];   end; for i:=1 to nn do   begin     wz:=locate(b[i]);     if (h[wz]=b[i]) then inc(sum);   end; if (sum=n)and(sum=nn) then write('A equals B') else if (sum<n)and(sum=nn) then write('B is a proper subset of A') else if (sum=n)and(sum<nn) then write('A is a proper subset of B') else if sum=0 then write('A and B are disjoint') else write('I''m confused!');end.
原创粉丝点击