当前位置:网站首页>Zzulioj:1201: mode problem
Zzulioj:1201: mode problem
2022-07-04 05:17:00 【A Bai|】
1201: The question of mode
The time limit : 1 Sec Memory limit : 128 MB
Submit : 2504 solve : 1635
[ state ] [ Discussion board ] [ Submit ] [ Propositional person : External import ]Title Description
Given to contain n Multiple sets of elements S, Each element in S The number of occurrences in is called the multiplicity of the element . Multiple sets S The element with the largest multiplicity is called mode .
for example ,S={1,2,2,2,3,5}. Multiple sets S What is the mode 2, Its multiplicity is 3.
Programming tasks :
For a given by n A multiple set of natural numbers S, Programming calculation S Mode and multiplicity of .Input
The first 1 Row multiset S The number of elements in n(n<=50000); Next n In line , Each line has a natural number .
Output
Output file has 2 That's ok , The first 1 OK, give me a few , The first 2 A row is a multiplicity .( If there are multiple modes , Output only the smallest )
The sample input Copy
6 1 2 2 2 3 5Sample output Copy
2 3source / classification
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef struct most {
int num, fre;
}M;
M m[50001];
int max_ = -1;
static int flag = 0;
void quicksort(int l, int r) {// Quick line up , Find the maximum value by the way
int p = l;
if (l < r) {
int index = p + 1;
for (int i = index; i <= r; i++) {
if(flag == 0) // Find the maximum value in the first call , Prevent wasting time
max_ = max(max_, m[i].fre);
if (m[i].num < m[p].num) {
M t = m[i];
m[i] = m[index];
m[index] = t;
index++;
}
}
M t = m[p];
m[p] = m[index - 1];
m[index - 1] = t;
flag++;
quicksort(l, p - 1);
quicksort(p + 1, r);
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
int low, t, sum = 0;
for (int i = 0; i < n; i++) {// save
t = 0;
cin >> low;
for (int j = 0; j < sum; j++) {
if (m[j].num == low) {
m[j].fre++;
t = 1;
break;
}
}
if (t == 0) {
m[sum].num = low;
m[sum].fre++;
sum++;
}
}
quicksort(0, sum - 1);// Sort
for (int i = 0; i < sum; i++) {
if (m[i].fre == max_) {// If the maximum value is found , Prove that you found that number
cout << m[i].num << '\n' << m[i].fre;
break;
}
}
return 0;
}边栏推荐
- [matlab] communication signal modulation general function interpolation function
- ETCD数据库源码分析——初始化总览
- Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis
- 令人头痛的延时双删
- [paper summary] zero shot semantic segmentation
- 2022广东省赛——编码信息获取 解析flag
- Flask
- Flink1.13 basic SQL syntax (II) join operation
- KMP匹配字符串
- [matlab] matlab simulation of modulation system - power spectrum and coherent demodulation of AM modulated signal
猜你喜欢

【QT】定时器

Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis

RSA加密应用常见缺陷的原理与实践

如何构建属于自己的知识引擎?社群开放申请

【QT】制作MyComboBox点击事件
![[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术](/img/87/e0469e280365ed0261e2b551ebd888.png)
[技术发展-25]:广播电视网、互联网、电信网、电网四网融合技术

TCP state transition diagram

2022年T电梯修理操作证考试题库及模拟考试
![[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre](/img/3e/b5df691ca1790469eb1b4e8ea5b4c0.png)
[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre

如何使用postman实现简单的接口关联【增删改查】
随机推荐
Annex I: power of attorney for 202x XXX attack and defense drill
appliedzkp zkevm(11)中的EVM Proof
抓包整理外篇fiddler———— 会话栏与过滤器
[matlab] matlab simulation - simulate the AM modulation process of the modulation system
如何使用postman实现简单的接口关联【增删改查】
[matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (cosine roll off forming pulse)
Just do it with your hands 7 - * project construction details 2 - hook configuration
Secondary vocational group network security - memory Forensics
VSCode的有用插件
c语言经典指针和数组笔试题解析
IP时代来临,电竞酒店如何借好游戏的“东风”?
2022 a special equipment related management (elevator) examination questions simulation examination platform operation
2022g2 power station boiler stoker special operation certificate examination question bank and answers
Simulink与Arduino串口通信
Daily question brushing record (12)
Integer type of C language
如何构建属于自己的知识引擎?社群开放申请
【MATLAB】MATLAB 仿真 — 窄带高斯白噪声
[matlab] matlab simulates digital bandpass transmission system ask, PSK, FSK system
Notes on the paper "cross view transformers for real time map view semantic segmentation"