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;
}

全部评论

相关推荐

10-09 17:17
已编辑
门头沟学院 Java
活泼的代码渣渣在泡池...:同学你好,我也是学院本,后天要面这个亚信科技,是实习,请问问题都啥样呀,我项目就做了网上的,这是第一次面试
投递多益网络等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务