第一行一个整数。
接下来个整数
。
输出一行,一个整数表示最少堆数。
4 4 2 4 3
2
一个半径为4的大饼一堆,另外一个半径为2,3,4的大饼叠在一堆
7 4 9 7 7 3 3 2
2
一种情况为:9,7,4,3,2 一堆,7,3一堆
9 2 10 3 9 2 5 3 2 9
3
#include <iostream>
#include <unordered_map>
using namespace std;
int main()
{
int n;
cin >> n;
unordered_map<int, int> data;
int res{0};
while (n--)
{
int temp;
cin >> temp;
++data[temp];
res = max(res, data[temp]);
}
cout << res;
return 0;
} import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
String[] strs = br.readLine().split(" ");
HashMap<Integer, Integer> counter = new HashMap<>();
for(int i = 0; i < n; i++){
int cake = Integer.parseInt(strs[i]);
counter.put(cake, counter.getOrDefault(cake, 0) + 1);
}
int count = 0;
while(!counter.isEmpty()){
List<Integer> keys = new ArrayList<>(counter.keySet());
for(int key: keys){
if(counter.get(key) == 1){
counter.remove(key);
}else{
counter.put(key, counter.get(key) - 1);
}
}
count++;
}
System.out.println(count);
}
} #include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int n;
cin >> n;//输入n
int* a = new int[n];//创建array a,数量为n
for (int i = 0; i < n; i++)
{
cin >> a[i];//输入所有的数字
}
sort(a,a+n);//对 array a 进行从小到大的排序
int max = 1;//历史出现频率最大的数字的 出现次数,最小为1
int num = 1;//当前数字出现次数,最小也为1
for (int j = 1; j < n; j++)//从第二个数字开始
{
if (a[j] == a[j - 1])//如果当前数字和前一个数字相同
{
num++;//则当前数字出现次数+1
if (num > max)//如果当前数字出现频率超过历史最大值
{
max = num;//则当前数字出现的频率覆盖历史最大值
}
}
else {//若当前数字和前一个不一样
num = 1; //则重置当前数字出现次数
}
}
cout << max << endl;//输出历史出现频率最高的数字的次数
}