codeforce Gym - 101597E(暴力排序)
E. Collection
time limit per test
2.0 s memory limit per test
64 MB input
standard input output
standard output Alan recently started collecting the cards of the well known "Famous Computer Scientists" card game by the ACM. As buying cards is starting to get expensive, he would like to start trading. To do this, he needs to know the number of duplicate cards in his collection. Write a program to help him calculate this number.
Input
The first line contains a single integer n, the number of cards in Alan's collection. The second line contains n integers ci, where ci is the id of the i-th card. It holds that 1 ≤ n ≤ 200'000 and 0 ≤ ci ≤ 109.
Output
Print a single integer denoting the number of duplicates, that is the number of cards he can safely trade whilst still having the same number of unique cards.
Examples
input
Copy
4 127 0 0 1
output
Copy
1
input
Copy
6 1 1 1000000 1 1 1
output
Copy
4
问你这些数里重复的有多少~~用一个数组存下来排序~~然后看这个和之前的拉个数是否一样就好了~~贼水
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
long long int m[200005];
int main()
{
int n;
scanf("%d", &n);
for (int s = 1; s <= n; s++)
{
scanf("%lld", &m[s]);
}
m[0] = -1;
sort(m + 1, m + n + 1);
int maxn = 0;
int tem = 0;
for (int s = 1; s <= n; s++)
{
if (m[s] == m[s - 1])
{
tem++;
}
}
cout << tem << endl;
return 0;
}
提示