1 条题解

  • 0
    @ 2026-9-30 12:33:32

    C++ :

    
    #include <cstdio>
    int main(){
        int n, m;
        if(scanf("%d %d", &n, &m) != 2) return 0;
        static int a[1005], gone[1005];
        for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
        for(int i = 0; i < m; i++){ int b; scanf("%d", &b); gone[b] = 1; }
        /* 剩下的球按重量计数,同重量两两配对 -> C(cnt,2) */
        static int cnt[105];
        for(int i = 1; i <= n; i++) if(!gone[i]) cnt[a[i]]++;
        long long ans = 0;
        for(int w = 1; w <= 100; w++) ans += (long long)cnt[w] * (cnt[w] - 1) / 2;
        printf("%lld\n", ans);
        return 0;
    }
    
    
    • 1

    信息

    ID
    2581
    时间
    1000ms
    内存
    256MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者