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, 800x600), 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 (<=800) and N (<=600) which are the resolutions of the image. Then N lines follow, each contains M digital colors in the range [0, 224). 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
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
map<int, int> mp;
int main(){
int M, N, maxColor, maxN = -, temp;
scanf("%d %d", &M, &N);
for(int i = ; i < M; i++){
for(int j = ; j < N; j++){
scanf("%d", &temp);
if(mp.count(temp) == ){
mp[temp] = ;
}else{
mp[temp] = mp[temp] + ;
}
if(mp[temp] > maxN){
maxN = mp[temp];
maxColor = temp;
}
}
}
printf("%d", maxColor);
cin >> N;
return ;
}

总结:

1、题意:找出出现次数最多的数。 由于数字的范围很大,将其作为下标建立哈希表将会开一个超限的数组。所以使用map<int, int>。

A1054. The Dominant Color的更多相关文章

  1. 【算法笔记】A1054 The Dominant Color

    1054 The Dominant Color (20 分)   Behind the scenes in the computer's memory, color is always talked ...

  2. PAT甲级——A1054 The Dominant Color

    Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of i ...

  3. 1054. The Dominant Color (20)

    时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Behind the scenes in the compute ...

  4. PAT 1054 The Dominant Color

    1054 The Dominant Color (20 分)   Behind the scenes in the computer's memory, color is always talked ...

  5. PAT 甲级 1054 The Dominant Color (20 分)

    1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...

  6. PAT 1054 The Dominant Color[简单][运行超时的问题]

    1054 The Dominant Color (20)(20 分) Behind the scenes in the computer's memory, color is always talke ...

  7. PAT 甲级 1054 The Dominant Color

    https://pintia.cn/problem-sets/994805342720868352/problems/994805422639136768 Behind the scenes in t ...

  8. pat 1054 The Dominant Color(20 分)

    1054 The Dominant Color(20 分) Behind the scenes in the computer's memory, color is always talked abo ...

  9. 1054 The Dominant Color (20)(20 分)

    Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of i ...

随机推荐

  1. 记录:EM 算法估计混合高斯模型参数

    当概率模型依赖于无法观测的隐性变量时,使用普通的极大似然估计法无法估计出概率模型中参数.此时需要利用优化的极大似然估计:EM算法. 在这里我只是想要使用这个EM算法估计混合高斯模型中的参数.由于直观原 ...

  2. zabbix监控主机cpu达到80%后报警

    在zabbix监控中,默认cpu监控模板中的触发器,当负载在一定时间内(比如最近5分钟)超过5以上为报警阀值.但是在实际场景中,由于服务器配置不一样,这个默认的cpu触发器用起来意义就不大了,这时候就 ...

  3. C. Oh Those Palindromes

    题意 给以一个字符串,让你重排列,使得回文子串的数目最多 分析 对于一个回文串,在其中加入一些字符并不会使回文子串的个数增加,所以对于相同的字符一起输出即可,我是直接排序 代码 #include< ...

  4. Linux 第八周实验 进程的切换和系统的一般执行过程

    姬梦馨 原创作品 <Linux内核分析>MOOC课程:http://mooc.study.163.com/course/USTC-1000029000 第八讲 进程的切换和系统的一般执行过 ...

  5. myeclipse快捷方式汇总

    选择你要注释的那一行或多行代码,按Ctrl+/即可,取消注释也是选中之后按Ctrl+/即可. 如果你想使用的快捷键的注释是的话,那么你的快捷键是ctrl+shift+/我以前都是手动注释的,直接打// ...

  6. ☆C++学习心得

    C++是我进大学的学的第一种编程语言,在高中的时候有电脑课,有教过部分的VB语言,所以其实对编程也并不是非常的陌生,刚开是上课也觉得感觉不难,都懂,没多少课后,恍了个神..居然听不懂了!老师经常让我们 ...

  7. 战神答题APP 无敌结束版

    APP发布了哦~~     多多捧场~ http://anzhuoyuan.com/app/info/appid/242381.html 还有github https://github.com/784 ...

  8. 《Multiplayer Game Programming》阅读笔记

    在图书馆发现一本<网络多人游戏架构与编程>-- Joshua Glazer, Sanjay Madhav 著.书挺新的,17年出版的,内容很有趣,翻一翻可以学到不少在<计算机网络&g ...

  9. ASP.NET MVC应用安全性(一)——自定义错误处理

    很多 ASP.NET  MVC 开发者都会写出高性能的代码,很好地交付软件,等等.但是却并没有安全性方面的计划. 有一种攻击是攻击者截获最终用户提交的表单数据,将其改变再将修改后的数据发送到服务器. ...

  10. EL表达式和JSTL标签库

    expresion language表达式语言 可以输出表达式的值.跟jsp的表达式脚本一样.计算表达式的值后输出.  EL表达式出现的目的是为了使JSP写起来更加简单,让jsp的代码更佳简化. 1. ...