文章

119

粉丝

68

获赞

92

访问

20.1k

头像
数字模式的识别 题解:必须用unordered_map,否则超时
P1057
发布于2025年2月10日 14:09
阅读数 66

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	while(cin>>n){
	    map<int,int>a;
	    while(n--){
	        int x;
	        cin>>x;
	        a[x]++;
	    }
	    int max=INT_MIN,tag=INT_MIN;
	    for(auto x:a){
	        if(x.second>=max){
	            tag=x.first;
	            max=x.second;
	        }
	    }
	    cout<<tag<<endl;
	}
}

map的效率不如unordered_map效率高,在极大数据量的时候会超时

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发