A1054 The Dominant Color (20分)

Posted tsruixi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了A1054 The Dominant Color (20分)相关的知识,希望对你有一定的参考价值。

一、技术总结

  1. 这个题目也是使用map STL来解决问题。
  2. 直接使用map<int, int>,同时题目规定是严格的Dominate Color,只要有超过一半的数,就可以输出,然后return 0;

二、参考代码

#include<iostream>
#include<map> 
using namespace std;
int main(){
    int m, n;
    scanf("%d %d", &m, &n);
    map<int, int> count;
    int half;
    half = m * n / 2;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            int temp;
            scanf("%d", &temp);
            count[temp]++;
            if(count[temp] > half){
                printf("%d", temp);
                return 0;
            }
        }
    }
    return 0;
}

以上是关于A1054 The Dominant Color (20分)的主要内容,如果未能解决你的问题,请参考以下文章