当前位置:网站首页>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 - low pass filter
- 基于单片机的太阳能杀虫系统
- Li Kou's 300th weekly match
- 我们认为消费互联网发展到最后,依然会局限于互联网行业本身
- Annex 4: scoring criteria of the attacker docx
- Electronic components mall and data manual download website summary
- 【MATLAB】MATLAB 仿真 — 低通高斯白噪声
- KMP匹配字符串
- Remote desktop client RDP
- 2022 a special equipment related management (elevator) examination questions simulation examination platform operation
猜你喜欢
Public inputs in appliedzkp zkevm (13)
LM小型可编程控制器软件(基于CoDeSys)笔记二十一:错误3703
【QT】定时器
Programming example of stm32f1 and stm32subeide -74hc595 drives 4-bit 7-segment nixie tube
TCP状态转换图
企业级日志分析系统ELK(如果事与愿违那一定另有安排)
Fault analysis | mongodb 5.0 reports an error, and the legal instruction solves it
空洞卷积、可变形卷积、可变形ROI Pooling
Simulated small root pile
2022年R2移动式压力容器充装复训题库及答案
随机推荐
Notepad++ -- display related configurations
【MATLAB】MATLAB 仿真模拟调制系统 — AM 已调信号的功率谱与相干解调
Error response from daemon: You cannot remove a running container 8d6f0d2850250627cd6c2acb2497002fc3
Simulated small root pile
Secondary vocational group network security - memory Forensics
When using flash to store parameters, the code area of flash is erased, which leads to the interrupt of entering hardware error
[matlab] matlab simulation modulation system FM system
2022 question bank and answers for safety management personnel of hazardous chemical business units
Annex 2-2 confidentiality commitment docx
Using jsts in esmodule environment
Fault analysis | mongodb 5.0 reports an error, and the legal instruction solves it
2022G2电站锅炉司炉特种作业证考试题库及答案
LM小型可编程控制器软件(基于CoDeSys)笔记二十二:错误4268/4052
Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)
Several smart watch related chips Bluetooth chip low power consumption
力扣 第 300 场周赛
[matlab] communication signal modulation general function interpolation function
小程序毕业设计---美食、菜谱小程序
LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052
Zhongke panyun-2022 Guangdong Trojan horse information acquisition and analysis