A1054. 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, 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的更多相关文章
- 【算法笔记】A1054 The Dominant Color
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ...
- 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 ...
- 1054. The Dominant Color (20)
时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Behind the scenes in the compute ...
- PAT 1054 The Dominant Color
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ...
- PAT 甲级 1054 The Dominant Color (20 分)
1054 The Dominant Color (20 分) Behind the scenes in the computer's memory, color is always talked ab ...
- PAT 1054 The Dominant Color[简单][运行超时的问题]
1054 The Dominant Color (20)(20 分) Behind the scenes in the computer's memory, color is always talke ...
- PAT 甲级 1054 The Dominant Color
https://pintia.cn/problem-sets/994805342720868352/problems/994805422639136768 Behind the scenes in t ...
- pat 1054 The Dominant Color(20 分)
1054 The Dominant Color(20 分) Behind the scenes in the computer's memory, color is always talked abo ...
- 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 ...
随机推荐
- easyui datagrid remoteSort的实现 Controllers编写动态的Lambda表达式 IQueryable OrderBy扩展
EF 结合easy-ui datagrid 实现页面端排序 EF动态编写排序Lambda表达式 1.前端页面 var mainListHeight = $(window).height() - 20; ...
- React.js 入门与实战之开发适配PC端及移动端新闻头条平台课程上线了
原文发表于我的技术博客 我在慕课网的「React.js 入门与实战之开发适配PC端及移动端新闻头条平台」课程已经上线了,文章中是目前整个课程的大纲,以后此课程还会保持持续更新,此大纲文档也会保持更新, ...
- 软件工程附加篇章:进阶四则运算和Core对接
0x01 :计算模块(Core)和前端对接 首先特别结对编程刘乾组(SivilTaram)提供的计算模块(Core),http://www.cnblogs.com/SivilTaram/p/48599 ...
- linux内核分析程序破解实践报告
- LINUX内核分析第七周学习总结
LINUX内核分析第七周学习总结 标签(空格分隔): 20135328陈都 陈都 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.c ...
- spring中通过JNDI、DBCP、C3P0配置数据源
JNDI配置数据源 1.首先在tomcat的server.xml中配置数据源信息,找到Context,然后在里边加入如下代码 <Context docBase="SpringDemo& ...
- python 中的三元表达式及lambda
一.三元表达式 举一个简单的列子,很多地方都有这样的规定,比如用水或者用电,假设用水价格为3R/立方米,当你每个月用超过7立方米后,超出的水按照3.3R/立方米计价.然后写一个程序计算一个家庭每月的水 ...
- css3-盒模型新增属性
box-shadow:跟text-shadow类似,可多层叠加 box-shadow:[inset] x y blur [spread] color inset:投影方式,inset内投影,不加参数外 ...
- shell脚本--制作自己的服务脚本
首先注意一下,我用的环境是centos6.5,中间有一些操作和在Ubuntu上有一些地方的操作是不同的, 编写脚本 首先看一个实例:假设有一个test的服务,可以通过命令对test进行启动.关闭或者重 ...
- JQuery基础-- Ajax
基本格式: get: $.get("url",data,function(res){ #..... }) post: $.post("url",data ...