当前位置:网站首页>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;
}边栏推荐
- With the advent of the IP era, how can E-sports hotels take advantage of the "east wind" of games?
- [untitled]
- TCP state transition diagram
- Just do it with your hands 7 - * project construction details 2 - hook configuration
- Get the ID of the record just inserted from laravel
- 由于使用flash存放参数时,擦除掉了flash的代码区导致进入硬件错误中断
- Annex 2-2 confidentiality commitment docx
- PostgreSQL has officially surpassed mysql. Is this guy too strong!
- appliedzkp zkevm(11)中的EVM Proof
- [matlab] general function of communication signal modulation Fourier transform
猜你喜欢

TCP状态转换图

Sécurité du réseau dans les écoles professionnelles secondaires - preuve de mémoire

中科磐云—D模块解析以及评分标准

数据标注是一块肥肉,盯上这块肉的不止中国丨曼孚科技
![[QT] timer](/img/df/5db6af851ef19f33fd7e7a7ed46586.png)
[QT] timer

Zhongke panyun-d module analysis and scoring standard

Flask

How to build your own knowledge engine? Community open application

C语言简易学生管理系统(含源码)

Simulink and Arduino serial port communication
随机推荐
Secondary vocational group network security - memory Forensics
中科磐云—D模块解析以及评分标准
2022g2 power station boiler stoker special operation certificate examination question bank and answers
2022危险化学品经营单位安全管理人员上岗证题库及答案
中科磐云—2022广西逆向解析思路
Several smart watch related chips Bluetooth chip low power consumption
Void convolution, deformable convolution, deformable ROI pooling
Roles of rollup components
海力士EMMC5.0及5.1系列对比详解
The second case analysis of the breakthrough of defense system from the perspective of the red team
[matlab] general function of communication signal modulation inverse Fourier transform
Zhongke Panyun - data analysis and forensics packet flag
企业级日志分析系统ELK(如果事与愿违那一定另有安排)
Ping port artifact psping
【MATLAB】MATLAB 仿真 — 低通高斯白噪声
LM小型可编程控制器软件(基于CoDeSys)笔记二十一:错误3703
Unity2d -- character moves and turns
[matlab] communication signal modulation general function - low pass filter
远程桌面客户端 RDP
flink1.13 sql基础语法(一)DDL、DML