Polycarp's Pockets(CodeForces - 1003A)最简便思维

欢迎访问https://blog.csdn.net/lxt_Lucia~~

宇宙第一小仙女\(^o^)/~~萌量爆表求带飞=≡Σ((( つ^o^)つ~ dalao们点个关注呗~~

 

Polycarp's Pockets(CodeForces - 1003A)

 

Description

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.

Input

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.

Output

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.

Examples

Input

6
1 2 4 3 3 2

Output

2

Input

1
100

Output

1

 

题意:

Polycarp有n个硬币,第i个硬币的价值为ai。他想把所有的硬币都放进自己的口袋里,但他不能把两个同样价值的硬币放在同一个口袋里,求把所有硬币放进口袋所需最少的口袋数。
例如,如果Polycarp得到了6个价值分别为 a = [ 1,2,4,3,3,3,2,2 ] 的硬币,那么他可以将这些硬币分配到以下两个口袋中:[1,2,3],[2,3,4],最少口袋数为2。。

 

思路:

不少人看完题后就先想到了子序列什么的还有各种排序,其实没有那么麻烦,此题只要求同价值的硬币不能放在一个口袋,并没有要按照价值上升或者一共有多少种放法之类的要求,我们只需要求出所需最少口袋数就可以了,至于其他的硬币怎么放,只要不把同种放在一个里面,随便放就可以。所以最少需要的口袋数就等于出现次数最多的价值

 

代码C++:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int a[1100]={0},ans=0,n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        a[x]++;
        ans=max(ans,a[x]);
    }
    cout<<ans<<endl;
}

 

代码C:

#include<stdio.h>
#include<string.h>
#include<iostream>

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们点个关注呗~~

 

 

 

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值