码迷,mamicode.com
首页 > 其他好文 > 详细

1054 The Dominant Color (20point(s)) Easy only once

时间:2020-02-21 18:08:21      阅读:54      评论:0      收藏:0      [点我收藏+]

标签:排序   iostream   names   pac   nbsp   ==   ring   简单的   mes   

基本思想:

无,简单的排序问题,注意pair排序的另解;

 

关键点:

无;

 

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector> 
#include<string>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
using namespace std;

int m, n;
map<int, int>mp;


int main() {
    cin >> m >> n;
    int a;
    for (int i = 0; i < m*n; i++) {
        cin >> a;
        if (mp.find(a) == mp.end()) {
            mp[a] = 1;
        }
        else {
            mp[a]++;
        }
    }
    int max = 0;
    map<int, int>::iterator fin;
    for (map<int,int>::iterator it = mp.begin(); it != mp.end(); it++) {
        if (it->second > max) {
            max = it->second;
            fin = it;
        }
    }
    if (fin->second > m*n / 2) {
        cout << fin->first;
    }
    return 0;
}

 

1054 The Dominant Color (20point(s)) Easy only once

标签:排序   iostream   names   pac   nbsp   ==   ring   简单的   mes   

原文地址:https://www.cnblogs.com/songlinxuan/p/12342084.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!