当前位置:网站首页>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;
}边栏推荐
- Notepad++--显示相关的配置
- Error response from daemon: You cannot remove a running container 8d6f0d2850250627cd6c2acb2497002fc3
- Flask
- LabVIEW错误对话框的出现
- appliedzkp zkevm(13)中的Public Inputs
- COMP1721 Creating Classes
- 抓包整理外篇fiddler———— 会话栏与过滤器
- 2022g2 power station boiler stoker special operation certificate examination question bank and answers
- Customize a pager needed in your project
- [technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid
猜你喜欢

ping端口神器psping

定制一个自己项目里需要的分页器

Secondary vocational group network security - memory Forensics

Notes on the paper "cross view transformers for real time map view semantic segmentation"

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

Character types of C language

Zhongke panyun-d module analysis and scoring standard

Public inputs in appliedzkp zkevm (13)

Capturing and sorting out external Fiddler -- Conversation bar and filter

TCP状态转换图
随机推荐
[paper summary] zero shot semantic segmentation
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
[matlab] matlab simulates digital baseband transmission system - digital baseband transmission system
LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052
TCP状态转换图
【MATLAB】MATLAB 仿真模拟调制系统 — DSB 系统
PostgreSQL has officially surpassed mysql. Is this guy too strong!
Zkevm (12) state proof of appliedzkp
Encryption and decryption
定制一个自己项目里需要的分页器
[matlab] general function of communication signal modulation Fourier transform
Evolution of system architecture: differences and connections between SOA and microservice architecture
Daily question brushing record (12)
Thread pool: use thread pool to optimize query speed
中科磐云—2022广西逆向解析思路
数据标注是一块肥肉,盯上这块肉的不止中国丨曼孚科技
KMP匹配字符串
2022 Guangdong provincial competition - code information acquisition and analysis flag
抓包整理外篇fiddler———— 会话栏与过滤器
The first introduction, stages and methods of defense system breakthrough from the perspective of the red team