大佬们,请问这个题最后为啥我需要加个1,谢谢
查看原帖
大佬们,请问这个题最后为啥我需要加个1,谢谢
1091827
sdcjdxzqh1楼主2023/12/25 20:38
#include<bits/stdc++.h>
using namespace std;
int a[1000005]={0};
long long s = 0, x = 0, i, n, b;
int main()
{
    cin >> n;
    for (i = 0; i < n; i++)
    {
        cin >> b;
        a[b]++;
    }
    for (i = 0; i < n; i++)
    {
        if (a[i] > 2)
            s += a[i] - 2;
        else if (a[i] == 1)
            x++;
    }
    if (s >= x)
        cout << s;
    else
        cout << (s+x+1)/2
    return 0;
}
2023/12/25 20:38
加载中...