题目描述
给定两个集合 A、B,集合内的任一元素 x 满足 1≤x≤
109
,并且每个集合的元素个数不大于
107
。我们希望求出 A、B 之间的关系,只需确定在 B 中但是不在 A 中的元素的个数即可。
输入格式
输入文件有两行,分别表示两个集合,每行的第一个整数为这个集合的元素个数(至少一个),然后紧跟着这个集合的元素(均为不同的正整数)。
输出格式
输出文件只有一个整数,即在 B 中但是不在 A 中的元素的个数即可。
样例数据1
输入
2 55 27
2 55 27
输出
0
样例数据2
输入
3 9 24 1995
2 9 24
输出
0
样例数据3
输入
3 1 2 3
4 1 2 3 4
输出
1
样例数据4
输入
3 1 2 3
3 4 5 6
输出
3
样例数据5
输入
2 1 2
2 2 3
输出
1
分析:哈希表模板,注意事项见集合A。
代码
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<iomanip>
#include<queue>
#include<set>
using namespace std;
int getint()
{
int sum=0,f=1;
char ch;
for(ch=getchar();!isdigit(ch)&&ch!='-';ch=getchar());
if(ch=='-')
{
f=-1;
ch=getchar();
}
for(;isdigit(ch);ch=getchar())
sum=(sum<<3)+(sum<<1)+ch-48;
return sum*f;
}
int a,b,x,s,maxx=111317;
int index[10111317];
int locate(int t)
{
int tmp=t%maxx;
while((index[tmp]!=0)&&index[tmp]!=t)
tmp++;
return tmp;
}
bool find(int t)
{
if(index[locate(t)]==t)
return true;
else
return false;
}
int main()
{
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
a=getint();
for(int i=1;i<=a;++i)
{
x=getint();
index[locate(x)]=x;
}
b=getint();
for(int i=1;i<=b;++i)
{
x=getint();
if(!find(x))
s++;
}
cout<<s<<'\n';
return 0;
}
本题结。