zoukankan      html  css  js  c++  java
  • 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 }
    永远渴望,大智若愚(stay hungry, stay foolish)
  • 相关阅读:
    bzoj2298 [HAOI2011]problem a
    P5504 [JSOI2011]柠檬
    洛谷P4383 [八省联考2018]林克卡特树
    [USACO17DEC]Standing Out from the Herd
    bzoj3926: [Zjoi2015]诸神眷顾的幻想乡
    dtoj4680. 红黑兔
    dtoj2099. 字符串查询( find)
    dtoj1721. 字符串生成器 ( strgen )
    dtoj4542. 「TJOI / HEOI2016」字符串
    loj2278. 「HAOI2017」字符串
  • 原文地址:https://www.cnblogs.com/h-hkai/p/12844611.html
Copyright © 2011-2022 走看看