SSL_1125 合集

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.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章