SSL1125 集合
来源:互联网 发布:小内存win10平板优化 编辑:程序博客网 时间:2024/05/17 04:24
题目大意
给定两个集合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.
0 0
- SSL1125 集合
- (ssl1125) 集合(normal)
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- 集合
- Sqlserver数据库 通过表触发器 实时通知应用程序
- 在 Linux 下将 PNG 和 JPG 批量互转的四种方法
- 分治 小车载人问题
- 广度优先遍历BFS
- Linux_3th_第1个linux驱动___编译空壳驱动程序
- SSL1125 集合
- 5.3 Swift函数的内部和外部参数
- NOIP2016愤怒的小鸟
- 求有向图的强连通分量<Tarjan>
- 5.4 Swift函数的默认参数
- Android Studio2.2下NDK开发初试
- 学习 Reflux 填过的坑
- Android NFC开发的那些坑
- 5.5 Swift参数的常量和变量特性