题解 | #Polycarp's Pockets#
Polycarps Pockets
https://ac.nowcoder.com/acm/problem/112909
题目描述
Polycarp has nnn coins, the value of the iii-th coin is aia_iai. 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]a = [1, 2, 4, 3, 3, 2]a=[1,2,4,3,3,2], he can distribute the coins into two pockets as follows: [1,2,3],[2,3,4][1, 2, 3], [2, 3, 4][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.
输入描述:
The first line of the input contains one integer nnn (1≤n≤1001 \le n \le 1001≤n≤100) — the number of coins.
The second line of the input contains nnn integers a1,a2,…,ana_1, a_2, \dots, a_na1,a2,…,an (1≤ai≤1001 \le a_i \le 1001≤ai≤100) — values of coins.
输出描述:
Print 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.
#include<iostream> using namespace std; int main() { int n, * a; cin >> n; a = new int[n]; int max = 0; int sum[105] = { 0 }; for (int i = 0; i < n; i++) { cin >> a[i]; sum[a[i]]++; if (max < sum[a[i]]) max = sum[a[i]]; } cout << max; return 0; }