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 ...
随机推荐
- 解决Jira和Confluence访问打开越来越缓慢问题
Jira和Confluence部署在同一台服务器上,跑一段时间后,发现访问jira和confluence时,打开越来越缓慢.这是因为根据主机物理内存不同,默认的java虚拟机内存也会不同(一个较低值) ...
- Docker容器学习梳理 - Dockerfile构建镜像
在Docker的运用中,从下载镜像,启动容器,在容器中输入命令来运行程序,这些命令都是手工一条条往里输入的,无法重复利用,而且效率很低.所以就需要一 种文件或脚本,我们把想执行的操作以命令的方式写入其 ...
- linux系统最小化安装后的初始化脚本
作为运维人员,经常会初始化系统,系统在安装过程中基本都会选择最小化安装,这样安装好的系统里会缺少很多环境. 下面分享一个系统安装后的初始化脚本: #!/bin/bash #系统时最小化安装的,这里要安 ...
- PHP从入门到精通(四)
PHP数组中的常用函数汇总 为了更直观的讲解各函数的作用和用法,方便大家的理解,首先,我们来定义一个数组.下面各函数的操作将以本数组为例: $arr = array(1,2,3,4,5,6," ...
- Let the Balloon Rise HDU水题
题意 让你统计字符串最多的那个串,并输出 分析 直接用map统计,不断更新最大值即可 代码 #include<iostream> #include<algorithm> #in ...
- 作业20171130 final发布 成绩
申诉 对成绩有疑问或不同意见的同学,请在群里[@杨贵福]. 申诉时间截止2017年12月16日 17:00. 更新 第一周和第二周成绩分别应占比20%和10%,计算时刚好反了.所以同学们的最终成绩有变 ...
- 【2016.3.16】作业 VS2015安装&单元测试(1)
首先说下本机配置. CPU:Intel Atom x5-z8300 @1.44GHz 内存:2GB 操作系统:Windows10 家庭版 32位 硬盘:32GB 然后开始怒装visual studio ...
- LINUX内核分析第八周学习总结
LINUX内核分析第八周学习总结 标签(空格分隔): 20135328陈都 陈都 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.c ...
- java_web—JSP+Servlet+JavaBean
JSP -> Java Server Page 后端 jsp -> JavaScript 前端 JSP语法 1.JSP插入Java代码 三种形式: (1)<%! %> ( ...
- “数学口袋精灵”App的第三个Sprint计划----开发日记
一.现状 上一阶段基本完成一个小游戏,游戏具有:随机产生算式,判断对错功能.通过轻快的背景音乐,音效,给玩家提供一个良好的氛围. 二.任务认领 完成界面,基本功能后的后续任务: 冯美欣:设计&qu ...