题解:CF1956B Nene and the Card Game

· · 题解

这道题让我们得到的分数最小。

考虑最坏情况,只有自己手中有相同的两张牌才能得一分,那么问题就迎刃而解了,时间复杂度 O(\sum n)。

#include <bits/stdc++.h>
using namespace std;
int a[200005];
int vis[200005];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--) {
        memset(a, 0, sizeof a);
        memset(vis, 0, sizeof vis);
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
            vis[a[i]]++;
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            ans += (vis[i] == 2);
        }
        cout << ans << '\n';
    }
}

记录