zoukankan      html  css  js  c++  java
  • 1720: 集合

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    using namespace std;
    #define maxn 100005
    #define maxm 2000000
    int na,nb,now[maxm],prep[maxn],val[maxn];
    void read(int &x){
        x=0; int f=1; char ch;
        for (ch=getchar();!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
        for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0'; x*=f;
    }
    void Ha(int x){
        int pos=val[x]%maxm+1;
        prep[x]=now[pos],now[pos]=x;
    }
    bool search(int x){
        int pos=x%maxm+1; bool bo=0;
        for (int i=now[pos];i;i=prep[i]){
            if (val[i]==x){
                bo=1; break;
            }
        }
        return bo;
    }
    int main(){
        memset(now,0,sizeof(now));
        read(na);
        for (int i=1;i<=na;i++) read(val[i]),Ha(i);
        int ans=0;
        read(nb); int x;
        for (int i=1;i<=nb;i++){
            read(x);
            if (!search(x)) ans++;
        } printf("%d
    ",ans);
        return 0;
    }
    View Code

    1720: 集合

    Time Limit: 1 Sec  Memory Limit: 128 MB
    Submit: 12  Solved: 7
    [Submit][Status][Web Board]

    Description

    给定两个集合A、B,集合内的任一元素x满足1 ≤ x ≤ 10^9,并且每个集合的元素个数不大于10^5。我们希望求出只需确定在B 中但是不在 A 中的元素的个数即可

    Input

    输入两行,分别表示两个集合,每行的第一个整数为这个集合的元素个数(至少一个),然后紧跟着这个集合的元素(均为不同的正整数)

    Output

    在B 中但是不在 A 中的元素的个数即可

    Sample Input

    8 1 2 3 4 5 6 7 8
    6 2 3 4 5 6 7

    HINT

     

    Source

  • 相关阅读:
    python 代码片段17
    python 代码片段15
    python 代码片段14
    python 代码片段13
    python 代码片段12
    RBAC模型
    2、服务注册与发现-电影服务
    1、通过eureka创建注册中心
    prop与attr
    位运算,效率高
  • 原文地址:https://www.cnblogs.com/LHR-HY/p/6351507.html
Copyright © 2011-2022 走看看