(ssl1125) 集合(normal)
来源:互联网 发布:电信4g网络apn设置 编辑:程序博客网 时间:2024/06/06 06:36
Time Limit:2000MS
Memory Limit:65536K
Total Submit:562
Accepted:182
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
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!
Source
elba
题解:本题的思路是用哈希表来储存。
至于数组大小则决定了程序内存和程序速度(一般来说大小与内存成正比,与速度成反比,但数组太大反而会慢!)
本题范围大致在100000以上,各位可以通过用不同的数来找到最优的解题数组!
var a,b,c,f:array[0..125886]of longint; n,m,t,i,min,ans:longint; x,y:char;function try(t:longint):longint;var tmp:longint;begin tmp:=t mod 125887;//mod一个较大的质数 while (f[tmp]<>0) and (f[tmp]<>t) do//如果当前位置有数而且不是同一个数 tmp:=(tmp+1) mod 125887;//往后面找空位,mod是用来回到开头再找(形成环) try:=tmp;end;begin x:='B'; y:='A';//后面懒得判断来输出了 read(n); for i:=1 to n do read(a[i]); read(m); for i:=1 to m do read(b[i]); if m<=n then min:=m; if m>n then//如果a是b的子串,那么b一定比a长 begin t:=n; c:=a; x:='A'; n:=m; a:=b; y:='B'; m:=t; b:=c; min:=m; end; for i:=1 to n do f[try(a[i])]:=a[i];//将a里的数放进去 for i:=1 to m do if f[try(b[i])]<>b[i] then inc(ans);//如果有不同就累加 if ans=0 then//没有不同 if n=m then write('A equals B')//长度相等,一样 else write(x,' is a proper subset of ',y)//长度不等,其中一个是另一个的子串 else if ans=min then write('A and B are disjoint')//不同的个数为比较短的一个长度,则不同 else write('I''m confused!');//都不是end.
阅读全文
1 0
- (ssl1125) 集合(normal)
- SSL1125 集合
- SSL P1125 集合(normal)
- normal
- Normal
- Normal Mapping
- normal form
- normal transform
- Normal Distribute
- Normal Map
- vertex normal
- Normal Mapping
- normal distribution
- normal map
- normal equation
- 删边(normal)
- 删边(normal)
- 删边(normal)
- 计算1-1/2+1/3-1/4+...+1/n的两种方法
- 批量执行redis命令行(windows)
- Chrome浏览器跨域设置
- unbuntu vim 配置
- <Android> 文件夹和文件操作
- (ssl1125) 集合(normal)
- 关于jquery checkbox的一点问题
- 用c++实现推箱子
- Encog3Java-User.pdf翻译:第十章 使用自组织映射
- 《大话设计模式》之外观模式
- 数据可视化与数据分析之间不可替代性
- 【51nod 2026】Gcd and Lcm
- spring Security4 和 oauth2整合 注解+xml混合使用(替换6位的授权码)
- Kotlin