集合(normal)
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!
思路:
真子集:真子集(proper subset)是指如果集合A是集合B的子集,并且集合B中至少有一个元素不属于A,那么集合A叫做集合B的真子集
交集:数学上,两个集合和的交集是含有所有既属于又属于的元素,而没有其他元素的集合。
其实可以不用hash的,但是我就是闲得慌。
然后进入正题……
我们先用hash把A集合存入hash表,然后输入B集合时,判断一下是否在表中出现过,用ans来记录个数。
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#define fre(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
using namespace std;
const int MAX=2147483647;
const int N=1e6;
const int Mod=149994;
int a,a1,b,b1,hash[150000],ans;
int qy(int a) {return a%Mod;}
int dw(int a)
{
int yw=qy(a),i=0;
while(i<Mod&&hash[(yw+i)%Mod]&&hash[(yw+i)%Mod]!=a) i++;
return (yw+i)%Mod;
}
void cr(int a) {hash[dw(a)]=a;}
bool cz(int a) {return hash[dw(a)]==a?true:false;}
int main()
{
scanf("%d",&a);
for(int i=1;i<=a;i++) scanf("%d",&a1),cr(a1);
scanf("%d",&b);
for(int i=1;i<=b;i++) scanf("%d",&b1),ans+=cz(b1);
if(ans==a&&a==b) printf("A equals B");else
if(a==ans) printf("A is a proper subset of B");else
if(b==ans) printf("B is a proper subset of A");else
if(!ans) printf("A and B are disjoint");
else printf("I'm confused!");
return 0;
}