Set of hash tables

Problem Description

Given two sets, either within a set of elements A B x satisfies 1 ≤ x ≤ 10 ^ 9, and the number of elements in each set is not greater than 10,000. We want to find the relationship between A, B. But not only determining the number of elements of A to B in the.

Input File

The first line of the two numbers m and n each represent the number of A and B set of elements. The following are the two elements of the set A and set B.

Output file

A number representing the number of elements in A but not in B.

SAMPLE INPUT

5 6
1 3 8 4 9
4 8 9 10 12 13 

Sample Output

3

Restrictions and conventions

Time limit: 1s

Space limitations: 128MB

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int a[10001],b,m,n,ans(0),first[1000010],p=1000007,next[10001];
bool hash(int x)
{
    int k=x%p,pi(0);
    for(int i=first[k];i>0;i=next[i])
    if(a[i]==x) pi=1;
    if(pi==0) return true;
    return false;
}
int main()
{
    cin>>m>>n;
    for(int i=1;i<=m;i++)
    {
    cin>>a[i];
    next[i]=first[a[i]%p];
    first[a[i]%p]=i;
    }
    for(int j=1;j<=n;j++)
    {
    cin>>b;
    if(hash(b)) ans++;
    }
    cout << years;
    return  0 ; 
}

 

Guess you like

Origin www.cnblogs.com/hfang/p/11240013.html