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 ...
随机推荐
- Linux下环境变量配置方法梳理(.bash_profile和.bashrc的区别)
在linux系统下,如果下载并安装了应用程序,在启动时很有可能在键入它的名称时出现"command not found"的提示内容.如果每次都到安装目标文件夹内,找到可执行文件来进 ...
- B. Math
链接 [http://codeforces.com/contest/1062/problem/B] 题意 给你n,有两种操作要么乘以某个数,要么开根但必须开根后是整数才能开,问你最后能变成最小的数是多 ...
- Personal Reading Assignment 2 -读推荐文章有感以及项目开发目前总结
在经过个人作业和结对作业的磨练和现在正在进行的团队作业的考验中,我对自己软件开发的一点得失有了些许感悟,同时读了老师推荐的文章后,自己也是有了一些感受. 首先在“No Silver Bullet”一文 ...
- 结对项目——Core设计与实现
写在前面:关于结对编程 结对编程我一直认为是一种非常好的合作方式,他的形式主要是由一个人负责代码编写,另一个人则在一旁即时对写下的代码进行审查,这样可以大大减少代码实现方面的错误. 这次我的结对伙伴是 ...
- SpringMVC-RESTRUL___CRUD知识点总结
RESTful风格 <!-- 携带surveyId去后台 --><!-- RESTFUL风格:/xxx/23 --><!-- 接收方式:@PathVariable注解 - ...
- ASP.NET MVC缓存使用
局部缓存(Partial Page) 1.新建局部缓存控制器: public class PartialCacheController : Controller { // GET: /PartialC ...
- [转帖] cnblog新闻区 “40岁以上的员工,请自觉离开”
“40岁以上的员工,请自觉离开” 投递人 itwriter 发布于 2018-04-29 22:36 评论(9) 有2733人阅读 原文链接 [收藏] « » “准确地说,华为目前要裁掉的.清退的,是 ...
- 开发一个微信小程序实例教程
一.注册小程序账号 1.进入微信公众平台(https://mp.weixin.qq.com/),注册小程序账号,根据提示填写对应的信息即可.2.注册成功后进入首页,在 小程序发布流程->小程序开 ...
- JetBrains全系列破解
教程开始: 进入自己安装idea路径的bin目录下,将刚刚下载好的JetbrainsCrack.jar复制到此目录下: 还是在bin目录下,找到idea.exe.vmoptions和idea64.ex ...
- Guava的RateLimiter在单机限流中的正确用法
错误使用 在实现限流时,网上的各种文章基本都会提到Guava的RateLimiter,用于实现单机的限流,并给出类似的代码: public void method() { RateLimiter ra ...