欢迎访问https://blog.csdn.net/lxt_Lucia~~
宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~~
Polycarp has nn coins, the value of the ii-th coin is aiai. 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], he can distribute the coins into two pockets as follows: [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 nn (1≤n≤1001≤n≤100) — the number of coins.
The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤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.
6
1 2 4 3 3 2
2
1
100
1
题意:
Polycarp有n个硬币,第i个硬币的价值为ai。他想把所有的硬币都放进自己的口袋里,但他不能把两个同样价值的硬币放在同一个口袋里,求把所有硬币放进口袋所需最少的口袋数。
例如,如果Polycarp得到了6个价值分别为 a = [ 1,2,4,3,3,3,2,2 ] 的硬币,那么他可以将这些硬币分配到以下两个口袋中:[1,2,3],[2,3,4],最少口袋数为2。。
不少人看完题后就先想到了子序列什么的还有各种排序,其实没有那么麻烦,此题只要求同价值的硬币不能放在一个口袋,并没有要按照价值上升或者一共有多少种放法之类的要求,我们只需要求出所需最少口袋数就可以了,至于其他的硬币怎么放,只要不把同种放在一个里面,随便放就可以。所以最少需要的口袋数就等于出现次数最多的价值。
#include
#include
using namespace std;
int main()
{
int a[1100]={0},ans=0,n;
cin>>n;
for(int i=0;i>x;
a[x]++;
ans=max(ans,a[x]);
}
cout<
#include
#include
#include
using namespace std;
int main()
{
int a[101],n,k,max1=0;
scanf("%d",&n);
memset(a,0,sizeof(a));
for(int i=0;i<=n-1;i++){
scanf("%d",&k);
a[k]++; //记录每种价值出现的次数
max1=max(max1,a[k]); //记录价值最多出现的次数
}
printf("%d\n",max1);
return 0;
}
嗯没戳~ 就这么短.......... 又想麻烦了叭~
宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~~