集合Hash哈希
来源:互联网 发布:九阴绝学金身升级数据 编辑:程序博客网 时间:2024/06/09 11:11
集合(normal)Time Limit:2000MS Memory Limit:65536KTotal Submit:563 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
样例12 55 272 55 27样例23 9 24 19952 9 24样例33 1 2 34 1 2 3 4样例43 1 2 33 4 5 6样例52 1 22 2 3
Sample Output
样例1A equals B样例2B is a proper subset of A样例3A is a proper subset of B样例4A and B are disjoint样例5I'm confused!
//思路:很简单经典普通的hash,自己看吧,都可以作为模板了……
const max=1580089;//开大一点,不然效率会很低var f:array[0..max] of longint; a:array[0..1200000]of longint; ans,an,bn,j:longint;function locate(x:longint):longint;var i:longint;begin i:=x mod max; while (f[i]<>0)and(f[i]<>x)do inc(i);//确定位置存放f[-] f[i]:=x;end;procedure ok(x:longint);var i:longint;begin i:=x mod max; while (f[i]<>0)and(f[i]<>x) do i:=i+1;//寻找f[-] if f[i]=x then inc(ans);//判断啦,根据题意end;begin read(an); for j:=1 to an do begin read(a[j]); locate(a[j]); end; read(bn); for j:=1 to bn do begin read(a[j]); ok(a[j]);//我的想法是存入一个数组,另一个用来比较 end; if (an=bn)and(ans=an)and(ans=bn)then write('A equals B')else//利用an,bn的长度和ans的大小可以直接判断 if (an<bn)and(ans=an)then write('A is a proper subset of B')else if (an>bn)and(ans=bn)then write('B is a proper subset of A')else if (ans=0) then write('A and B are disjoint') else write('I''m confused!');//记得打'!!!!end.
阅读全文
0 0
- 集合Hash哈希
- 集合(hash)
- Hash集合的问题
- 集合(hash)
- hash+map 维护集合
- Redis + php 使用hash(哈希) ,zset(有序集合)实例
- 集合(1) list hash
- hash集合类型操作命令
- Hash 哈希
- 哈希hash
- 哈希 hash
- 哈希hash
- redis基础简介(二)- hash(哈希)、set(集合)、sorted set(有序集合)以及键操作
- redis 的无序集合和hash操作
- Java集合中基于hash的容器
- hash集合源码学习笔记(一)
- 【Hash】【二分查找】17.6.3 集合 题解
- java集合之hashMap的hash原理
- 查看APK的签名的方法
- BZOJ4059: [Cerc2012]Non-boring sequences
- 剑指offer—调整数组顺序使奇数位于偶数前面
- C++进阶—>_beginthreadex和CreateThread的区别和联系
- 人工智能发展中的道德困境
- 集合Hash哈希
- 矩阵中的路径
- 网站发布到服务器后cookie无法登录问题
- 网络传输Socket:用于文件传输、视频聊天
- jQuery制作的网页菜单导航
- 9、新手入手树莓派教程--WiringPi控制GPIO
- bzoj3506&1552 [Cerc2007][Cqoi2014]robotic sort 排序机械臂(splay)
- 分布式架构中一致性解决方案——Zookeeper集群搭建
- jvm探秘九:类加载机制之类加载器