A1054 The Dominant Color 难度2

2023-10-14 17:20
文章标签 color 难度 a1054 dominant

本文主要是介绍A1054 The Dominant Color 难度2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

  1. 题目描述

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, 800×600), 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,). 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
  1. 问题分析

  • 遍历这个图片,看哪个像素个数最多,可以使用hash数组(因为范围很大)或者map

  • 然后遍历map,找到最大的像素的key 即为dominat color

  • 如何读取M个数?scanf()循环就可以

  1. 代码

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <unordered_set>
#include <sstream>using namespace std;int main() {int M,N;map<long,int >mp;long color;scanf("%d %d",&M,&N);for(int i=0;i<N;i++){for(int j=0;j<M;j++){scanf("%ld",&color);mp[color]++;}}int maxcolornum = -1;long maxcolor = -1;for(auto it:mp){if(it.second>maxcolornum){maxcolornum = it.second;maxcolor = it.first;}}printf("%ld",maxcolor);
}
  1. 思考与收获

  • 注意使用long

  • 要获取最大值所在的key,不能使用max,max只能获取最大值

这篇关于A1054 The Dominant Color 难度2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/211971

相关文章

三色标记(Tri-color marking)

维基百科部分 原文 https://en.wikipedia.org/wiki/Tracing_garbage_collection#TRI-COLOR Because of these performance problems, most modern tracing garbage collectors implement some variant of the tri-color ma

HDU 1556 Color the ball (树状数组-- 区间更新,单点求值)

OJ题目 :点这里~~ 与 单点更新,区间求值 稍有不同,需要理解注意。 AC_CODE int n;int num[100002];int lowbit(int x){return x&(-x);}int sum(int x){int ret = 0;while(x > 0){ret += num[x];x -= lowbit(x);}return ret;}void ad

[C++] 将LONG类型的color值转换为RGB值

转换原理: The calculation is: (65536 * Blue) + (256 * Green) + (Red) 'Convert RGB to LONG: LONG = B * 65536 + G * 256 + R       'Convert LONG to RGB:  B = LONG \ 65536  G = (LONG - B * 65536) \ 256  R =

记一次解析Pantone Color TCX 色彩码

第一次尝试解析TCX 第二次尝试解析TPG 第三次一次到位TCX&TPG ①打开潘通·中国官网 ②在找寻潘通色彩一栏输入TCX,提交 ③浏览器F12,找到搜索结果所在的div,右键copy element ④文本文档修改文件类型为js,并粘贴上一部的结果,将其赋值给str str='<div class="colorInfo" id="fashionColorDiv"><a class

ABAP OOALV 颜色COLOR设置

文章目录 行颜色、列颜色、单元格颜色设置COLOR行颜色设定实现过程运行结果 列颜色的设置实现过程运行结果 设置单元格颜色完成过程运行结果1运行结果2 行颜色、列颜色、单元格颜色设置COLOR 行颜色设定 参考文章:https://blog.csdn.net/Leo520liang/article/details/138697189 实现过程 TYPES: BEG

SAT数学考试难度介绍

SAT考试不仅考察考生的学术水平、学术能力与学术素质,同时还检测考生的学术态度。考生在参加SAT考试时,答错题目要扣分。下面小编为大家具体介绍SAT数学考试难度有多大,希望可以供大家参考借鉴。   SAT数学(Mathematics共44道选择题和10道填空题,答题的时间是70分钟,允许使用计算器,每个区最开头会给出一些公式。   根据历年的SAT数学考试真题和大部分考生的实际竟也能来说,

SAT考试数学题型与难度解析

SAT 的数学部分在不考虑加试的情况下共有三个部分,总分800。其中两个部分是选择题,每题5 个选项,只有1 个是正确答案;另一个部分由选择题与自答题共同组成。整个数学部分共有44 道选择题和10 道自答题,总答题时间为70 分钟。   我们沿用《SAT 官方指南》上的题型分类进行解析,即数字运算,几何测量和数据分析等三大类别。很多时候还会出现以上三种类别的混合题型,如有些题目会将函数图像与

Dominant Indices【模板】长链剖分

~~~~~      Dominant Indices ~~~~~      总题单链接 对比重链剖分和长链剖分 ~~~~~      什么是重链剖分:根据子树的大小将树拆成多条互不相交的链。 ~~~~~      什么是长链剖分:根据字数的深度将树拆成多条互不相交的链。 ~~~~~      重链剖分中的重儿子:子树大小最大的儿子。 ~~~~~      长链剖分中的重儿子:

2024年华侨生联考英语真题全析:难度变化与备考策略

导读 在前面我们和大家一起分享了2024年华侨生联考各科真题的难度情况。今天我们就来和大家具体的看一下2024年港澳台华侨生联考英语真题试卷具体分析哈。 听力部分 今年的听力和去年的听力总体难度差别不大,一段听力材料对应一道听力题目(简称一对一)只有三道题,一对二有两道,一对三一道,一对五这种长对话有两道。听力题目中涉及到的词汇难度属于中等级别,遇到生词的概率很低,只要做到正常词汇积累,

poj 2154 Color(polya计数 + 欧拉函数优化)

http://poj.org/problem?id=2154 大致题意:由n个珠子,n种颜色,组成一个项链。要求不同的项链数目,旋转后一样的属于同一种,结果模p。 n个珠子应该有n种旋转置换,每种置换的循环个数为gcd(i,n)。如果直接枚举i,显然不行。但是我们可以缩小枚举的数目。改为枚举每个循环节的长度L,那么相应的循环节数是n/L。所以我们只需求出每个L有多少个i满足gcd(