1054 The Dominant Color

Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A strictly dominant color takes more than half of the total area. Now given an image of resolution M by N (for example, 8), you are supposed to point out the strictly dominant color.

Input Specification:

Each input file contains one test case. For each case, the first line contains 2 positive numbers: M (≤) and N (≤) which are the resolutions of the image. Then N lines follow, each contains M digital colors in the range [0). It is guaranteed that the strictly dominant color exists for each input image. All the numbers in a line are separated by a space.

Output Specification:

For each test case, simply print the dominant color in a line.

Sample Input:

5 3
0 0 255 16777215 24
24 24 0 0 24
24 0 24 24 24
 

Sample Output:

24

题意:

  给出一个矩阵,找出这个矩阵中出现次数最多的数字。

思路:

  运用map来统计矩阵中出现数字的次数。

Code:

 1 #include <bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 int main() {
 6     int n, m;
 7     cin >> n >> m;
 8     map<string, int> mp;
 9     string str;
10     for (int i = 0; i < m; ++i) {
11         for (int j = 0; j < n; ++j) {
12             cin >> str;
13             mp[str]++;
14         }
15     }
16     int maxn = -1;
17     for (auto it : mp) {
18         if (it.second > maxn) {
19             maxn = it.second;
20             str = it.first;
21         }
22     }
23     cout << str << endl;
24     return 0;
25 }

 

posted @ 2020-05-07 17:58  Veritas_des_Liberty  阅读(139)  评论(0编辑  收藏  举报