新展览有n张图片。第i幅画有美丽的人工智能。我们知道,每次一个来访者从一幅画到一幅更美的画,他都会变得快乐。 我们可以按任何顺序安排图片。从第一个到最后一个传递所有图片时,访客可能高兴的最大次数是多少?换句话说,我们可以按任意顺序重新排列a的元素。指数i的最大可能数目是多少(1≤≤-1),使得ai+1>ai。
Input
输入的第一行包含整数n(1≤≤1000)-绘制数量。 第二行包含序列a1,a2,…,an(1≤ai≤1000),其中ai表示第i幅画的美。
Output
打印一个整数-相邻对的最大可能数目,以便在最佳重新排列后ai+1>ai。
Examples
Input
5
20 30 10 50 40
Output
4
Input
4
200 100 100 200
Output
2
Note
In the first sample, the optimal order is: 10, 20, 30, 40, 50.
In the second sample, the optimal order is: 100, 200, 100, 200.
初看题目,不会呀,想着怎么来排序,但是也没有严格的递增或者递减的序列,然后又想,是不是数学的关系来做,发现也没有思路,难道是暴力遍历?看到大神的代码和思路。因为高兴只能会在两个画不一样美的时候,所以应该找最多的对数(两值不一样),就是最大的结果。例如100 200 100 200,最多的不同 的对数为2 ,10 20 30 40 50 为4 个。那下面怎么找这个最大对数?根据数学原理,总数减去相同数字(最多的那个)数量,就是最多的(因为可以任意摆放),知道这个那就可以AC了。
#include<stdio.h>
using namespace std;
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
#include<bits/stdc++.h>
const int maxn=1005;
typedef long long ll;
int main()
{
map<int,int>mp;
int n;
cin>>n;
int num;
int maxshu=-1;
for(int i=0;i<n;i++)
{
cin>>num;
mp[num]++;
if(maxshu<mp[num])
maxshu=mp[num];
}
cout<<n-maxshu<<endl;
return 0;
}