最多的相同数是1 , 它有3个------7-3 =4 ---bingo
样例2:
5 1 1 1 1 1
最多的相同数是 1 , 它有5个 -----5-5=0----bingo
原因比如这个例子:1 1 1 3 3 3 3 3 5 5 10
                              3  3  3  5  5  10  1  1  1  3  3 
这样对应起来,1 3 (从较小的数开始 ), 总有5( 相同数的最大长度)这个长度不能对应
代码:
#include <stdio.h>
#include <iostream>
#include <map>
#include <bits/stdc++.h>
using namespace std;
int main()
{
	map<int , int> M;
	int n , m , max = -99999;
	scanf("%d" , &n);
	for(int i = 0 ; i < n ; i++)
	{
		scanf("%d" , &m);
		M[m]+=1;
		if(M[m] > max)
		{
			max = M[m]; 
		}
	}
	printf("%d\n" , n-max);
	return 0;
} 
京公网安备 11010502036488号