. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array a=[1,2,4,3,3,2]
, he can distribute the coins into two pockets as follows: [1,2,3],[2,3,4].
Polycarp wants to distribute all the coins with the minimum number of used pockets. Help him to do that.
InputThe first line of the input contains one integer n
( 1≤n≤100) — the number of coins.
The second line of the input contains n
integers a1,a2,…,an ( 1≤ai≤100) — values of coins.
OutputPrint only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket.
Examples Input Copy 6 1 2 4 3 3 2 Output Copy 2 Input Copy 1 100 Output Copy 1题意:一共有n个数,要将n个数分开,每堆数字不能有相同的数字,求最少需要分成几堆
思路:同一堆不能有相同数字,则出现次数最多的数字必定每一堆都出现,则最少的堆数等于数字出现的最多次数
代码:
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std; const int N = 105; int vis[N]; int main(){ int n; cin>>n; int maxt=0; for(int i=0;i<n;i++){ int x; cin>>x; vis[x]++; maxt=max(maxt,vis[x]); } cout<<maxt<<endl; return 0; }