题意:有n枚硬币,每个硬币都有一个价值,你要把他们放进口袋,保证每个口袋的硬币价值不重复,输出最少的口袋数量。
题解:模拟 其实就是找里面重复金币的最大个数
c++:
#include<bits/stdc++.h>
using namespace std;
int n,x,a[110],ans;
int main()
{
cin>>n;
for(int i=0; i<n; i++)
cin>>x,a[x]++,ans=max(a[x],ans);
cout<<ans<<endl;
return 0;
}
python:
n=int(input())
a=input().split()
ans=[]
for i in a:
ans.append(a.count(i))
print(max(ans))
还可以这样写:
input()
l = input().split()
print(max(l.count(x) for x in l))