跳到正文

题解

题解:CF1956B Nene and the Card Game

lkrqwq约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年4月18日
篇幅
约 1 分钟
题目
CF1956B

版本

  1. v1当前

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

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

C++
#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';
    }
}

记录

原文