SSL1125 集合

题目大意

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

思路

时间复杂度o(n)。

代码

const
  maxn=400319;
var
  n,m,s:longint;
  hx:array [0..maxn] of longint;
function try(k:longint):longint;
var
  t:longint;
begin
  t:=k mod maxn;
  while (hx[t]<>0)and(hx[k]<>k) do
    t:=(t+1) mod maxn;
  try:=t;
end;
procedure init;
var
  t,i:longint;
begin
  read(n);
  for i:=1 to n do
    begin
      read(t);
      hx[try(t)]:=t;
    end;
end;
procedure main;
var
  i,t:longint;
begin
  read(m);
  for i:=1 to m do
    begin
      read(t);
      if hx[try(t)]<>t then inc(s);
    end;
end;
procedure print;
begin
  if (n=m) and (s=0) then
    begin
      write('A equals B');
      exit;
    end;
  if (n>m) and (s=0) then
    begin
      write('B is a proper subset of A');
      exit;
    end;
  if (m>n) and (n+s=m) then
    begin
      write('A is a proper subset of B');
      exit;
    end;
  if (s=m) then
    begin
      write('A and B are disjoint');
      exit;
    end;
  write('I''m confused!');
end;
begin
  init;
  main;
  print;
end.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值