ProgramAlgTrain/20240823/十四届蓝桥比赛/主要成分.cpp

49 lines
814 B
C++
Raw Normal View History

2024-09-17 10:55:15 +00:00
#include<iostream>
#include<map>
2024-08-23 13:44:31 +00:00
using namespace std;
2024-08-23 14:05:05 +00:00
typedef long long ll;
#ifdef OI
#define PV(v){cout<<#v<<" : "<<(v)<<endl;}
#else
#define PV(v)
#endif
2024-08-23 13:44:31 +00:00
int n;
2024-08-23 14:05:05 +00:00
map<ll,int> m;
ll readint();
2024-08-23 13:44:31 +00:00
int main(){
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
2024-08-23 14:05:05 +00:00
n=readint();
for(int i=1;i<=n;i++){
m[readint()]++;
}
int max_m=INT_MIN;
ll max_dir = -1;
for(auto i :m){
if(max_m<i.second){
max_m=i.second;
max_dir=i.first;
}
}
if(max_m>n/2){
cout<<max_dir<<endl;
}else{
cout<<"No"<<endl;
}
}
2024-08-23 13:44:31 +00:00
2024-08-23 14:05:05 +00:00
ll readint(){
int x=0,w=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-')w=-1;
ch=getchar();
}
while(isdigit(ch)){
x=x*10+(ch-'0');
ch=getchar();
}
return x*w;
2024-08-23 13:44:31 +00:00
}