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)
  • 相关阅读:
    脚本化css 脚本化内联样式 脚本化css类
    jquery插件,表单验证validation plugin的使用
    跨域
    自己做的一个可以用在pc端移动端上点星星评论
    优化Jquery,提升网页加载速度
    编写灵活、稳定、高质量的 HTML 和 CSS 代码的规范
    eclipse编辑js很慢
    sortable bootstrap
    draggable,droppable
    eclipse配置
  • 原文地址:https://www.cnblogs.com/h-hkai/p/12844611.html
Copyright © 2011-2022 走看看